# [SciPy-User] Sequence not work

3 messages
Open this post in threaded view
|

## [SciPy-User] Sequence not work

 HiI have to represent the following sequence:    and my code is as follows:#!/usr/bin/env python import matplotlib.pyplot as pltimport numpy as npnum_muestras = 100z = np.zeros(num_muestras)z[2] = 2.0  #En Python se cuenta desde el cerofor n in range(2,num_muestras-1):             z[n+1] = np.power(2,n-(1/2)) * (np.sqrt(1- np.sqrt(1-np.power(4,1-n) * np.power(z[n],2))) )        fig1 = plt.figure()ax = plt.gca()plt.ylabel('$z[n+1]=2^{n-1/2}\sqrt{1-\sqrt{1-4^{1-n}z[n]^{2}}}$') plt.xlabel('$n$')plt.grid()ax.plot(z)plt.show()but does not work, z should tend to pi. might be wrong? thanks in advance _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user
 On Wed, Mar 27, 2013 at 3:11 AM, El suisse wrote: HiI have to represent the following sequence: $\inline {z[2]=2}$  $\inline {z[n+1]=2^{n-1/2}\sqrt{1-\sqrt{1-4^{1-n}z[n]^{2}}}$  $\inline {n=2,3,4....}$ and my code is as follows:#!/usr/bin/env python import matplotlib.pyplot as pltimport numpy as npnum_muestras = 100z = np.zeros(num_muestras)z[2] = 2.0  #En Python se cuenta desde el cerofor n in range(2,num_muestras-1):             z[n+1] = np.power(2,n-(1/2)) * (np.sqrt(1- np.sqrt(1-np.power(4,1-n) * np.power(z[n],2))) )    (1/2) should be 0.5 . (1/2) gives 0, not 0.5. The division of integers in Python 2.x defaults to returning an integer, not a floating point number (for a variety of reasons that you can Google for if you want an explanation). -- Robert Kern _______________________________________________ SciPy-User mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/scipy-user