I created this function using python
import numpy as np
p1=1/2
def qud(x,p):
x_sqr = x**2
x_qud = x**3
pn=x_sqr*p
return x_sqr ,x_qud,pn
I need to iterate this function multiple times , by giving the value of pn in the previous iteration.
I tried this without a for loop like this,
First iteration : sqr1, qud1 ,pnew = qud(2,p1)
Second iteration : sqr2, qud2 ,pnew1 = qud(2,pnew)
where i have used the value pnew which obtained from the first iteration.
Third iteration : sqr3, qud3 ,pnew2 = qud(2,pnew1) so on.
Now i wanted to modify my code so that values are going to stored using a for loop , when the number of iterations are given .But my code didnt work.
My code as follows,
i=4
sqr = np.zeros(i)
qud = np.zeros(i)
p1 = np.zeros(i)
sqr[0],qud[0],p1[0] = qud(2,p1)
for j in range (1,3) :
sqr[j],qud[j],p1[j] = qud(2,p1[j-1])
can any one suggest anything so that this works ?
Thank you