viewgit/index.php:465 Only variables should be passed by reference [2048]

viewgit/index.php:466 Non-static method GeSHi::get_language_name_from_extension() should not be called statically [2048]

  1. #!/usr/bin/enb python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Sample script to generate a PNM image
  5. # of the Newton's fractal associated with
  6. # x^\alpha - 1 polynomial.
  7. #
  8.  
  9. def GetNewtonConvergenceSpeed(z, maxit = 255, eps = 10e-11, alpha = 3):
  10. """
  11. This function returns, given a complex number z,
  12. an integer between 0 and maxit representing the
  13. number of iteration to approximate a root of
  14. the polynomial x^\alpha - 1 = f(x) so that
  15. |f(x)| < eps.
  16. """
  17.  
  18. fz = pow(z, alpha) - 1
  19. iterations = 0
  20.  
  21. while (abs(fz) > eps and iterations < maxit):
  22.  
  23. # Usiamo una var temporanea per non dover
  24. # ricalcolare le parti di comuni di funzione
  25. # e derivata.
  26. t = pow(z, alpha - 1)
  27. fz = t * z - 1
  28. fpz = alpha * t
  29.  
  30.  
  31. # Questo per prevenire la divisione per zero
  32. # (tanto la nostra derivata si annulla solo lì)
  33. if (fpz == 0):
  34. return maxit
  35.  
  36. z = z - fz / fpz
  37. iterations += 1
  38.  
  39. return iterations
  40.  
  41. def Newton(size = 200):
  42. """Compute the newton's method on a net of points
  43. in the set { x + iy \in C | |x| < 2 and |y| < 2 }
  44. and fill the image matrix with the value returned
  45. by the GetNewtonConvergenceSpeed ()
  46. """
  47.  
  48. # Delta è l'ampiezza dell'intervallo fratto il numero di
  49. # divisioni - 1
  50. delta = 4 / float(size - 1)
  51.  
  52. # Creiamo gli indici su cui iterare
  53. x_values = xrange(0 , size)
  54. y_values = x_values
  55.  
  56.  
  57. # Apriamo il file dove salveremo il nostro lavoro
  58. # e scriviamo l'intestazione del file PNM.
  59. f = open("newton.pnm", 'w')
  60. f.write("P3\n")
  61. f.write(str(size) + " " + str(size) + "\n")
  62. f.write("255\n")
  63.  
  64. # Scriviamo la matrice su file
  65. for x in x_values:
  66. for y in y_values:
  67. value = GetNewtonConvergenceSpeed(complex(-2 + x * delta,
  68. -2 + y * delta))
  69. f.write( str(3 * value) + " " +
  70. str(5 * value) + " " +
  71. str(9 * value) + "\n")
  72. f.close ()
  73.  
  74.  
  75. if __name__ == "__main__":
  76.  
  77. Newton (500)