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. print " => Iterating on %f + i%f" % (z.real, z.imag)
  19.  
  20. fz = pow(z, alpha) - 1
  21. iterations = 0
  22.  
  23. while (abs(fz) > eps and iterations < maxit):
  24. t = pow(z, alpha - 1)
  25. fz = t * z - 1
  26. fpz = alpha * t
  27.  
  28. # Questo per prevenire la divisione per zero
  29. # (tanto la nostra derivata si annulla solo lì)
  30. if (fpz == 0):
  31. return maxit
  32.  
  33. z = z - fz / fpz
  34. iterations += 1
  35.  
  36. return iterations
  37.  
  38. def Newton(size = 200):
  39. """Compute the newton's method on a net of points
  40. in the set { x + iy \in C | |x| < 2 and |y| < 2 }
  41. and fill the image matrix with the value returned
  42. by the GetNewtonConvergenceSpeed ()
  43. """
  44.  
  45. # Delta è l'ampiezza dell'intervallo fratto il numero di
  46. # divisioni - 1
  47. delta = 4 / float(size - 1)
  48. print " => delta = %f" % delta
  49.  
  50. x_values = range(0 , size)
  51. y_values = x_values
  52.  
  53. image = []
  54.  
  55. for x in x_values:
  56. image.append([])
  57. for y in y_values:
  58. image[x_values.index(x)].append(
  59. GetNewtonConvergenceSpeed(complex(-2 + x * delta,
  60. -2 + y * delta)))
  61.  
  62. f = open("prova.pnm", 'w')
  63. f.write("P3\n")
  64. f.write(str(size) + " " + str(size) + "\n")
  65. f.write("255\n")
  66.  
  67.  
  68. for x in x_values:
  69. for y in y_values:
  70. value = image[x][y]
  71. f.write( str(3 * value) + " " +
  72. str(5 * value) + " " +
  73. str(9 * value) + "\n")
  74.  
  75.  
  76. if __name__ == "__main__":
  77.  
  78. Newton (1024)