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. from numpy import linspace
  10.  
  11. def GetNewtonConvergenceSpeed(z, maxit = 255, eps = 10e-11, alpha = 3):
  12. """
  13. This function returns, given a complex number z,
  14. an integer between 0 and maxit representing the
  15. number of iteration to approximate a root of
  16. the polynomial x^\alpha - 1 = f(x) so that
  17. |f(x)| < eps.
  18. """
  19.  
  20. fz = pow(z, alpha) - 1
  21. iterations = 0
  22.  
  23. while (abs(fz) > eps and iterations < maxit):
  24.  
  25. # Usiamo una var temporanea per non dover
  26. # ricalcolare le parti di comuni di funzione
  27. # e derivata.
  28. t = pow(z, alpha - 1)
  29. fz = t * z - 1
  30. fpz = alpha * t
  31.  
  32.  
  33. # Questo per prevenire la divisione per zero
  34. # (tanto la nostra derivata si annulla solo lì)
  35. if (fpz == 0):
  36. return maxit
  37.  
  38. z = z - fz / fpz
  39. iterations += 1
  40.  
  41. return iterations
  42.  
  43. def Newton(size = 200):
  44. """Compute the newton's method on a net of points
  45. in the set { x + iy \in C | |x| < 2 and |y| < 2 }
  46. and fill the image matrix with the value returned
  47. by the GetNewtonConvergenceSpeed ()
  48. """
  49.  
  50.  
  51. # Creiamo gli indici su cui iterare
  52. x_values = linspace(-2,2,size,True)
  53. y_values = x_values
  54.  
  55.  
  56. # Apriamo il file dove salveremo il nostro lavoro
  57. # e scriviamo l'intestazione del file PNM.
  58. f = open("newton.pnm", 'w')
  59. f.write("P3\n")
  60. f.write(str(size) + " " + str(size) + "\n")
  61. f.write("255\n")
  62.  
  63. # Scriviamo la matrice su file. Salviamola prima però
  64. # in una stringa. Sì, occupa un sacco di RAM ma tanto
  65. # quella in genere non manca, e le scritture ripetute
  66. # sono esose di risorse.
  67. fileContent = ""
  68. for x in x_values:
  69. for y in y_values:
  70. value = GetNewtonConvergenceSpeed(complex(x,y))
  71. fileContent += " ".join([str(3*value), str(5*value), str(9*value)]) + "\n"
  72. f.write(fileContent)
  73. f.close ()
  74.  
  75.  
  76. if __name__ == "__main__":
  77.  
  78. Newton (500)