I wrote follwing code using Python
import numpy as np
x1=np.array([1,2,3,4])
p1=np.array([.1,.2,.3,.4])
def fun1 (x_vec,p_vec):
x11=np.zeros(len(x_vec))
p11=np.zeros(len(p_vec))
for i in range (0,len(x_vec)):
x11[i] =x_vec[i]**2
p11[i]=x11[i]*p_vec[i]
return x11 ,p11
First Iteration
x2=np.array(len(x1))
p2=np.array(len(p1))
x2 ,p2 = fun1(x1,p1)
Second Iteration
x3=np.array(len(x1))
p3=np.array(len(p1))
x3 ,p3 = fun1(x1,p2)
So in the second iteration, I used p2 which was obtained from the previous iteration.
Third Iteration
x4=np.array(len(x1))
p4=np.array(len(p1))
x4 ,p4 = fun1(x1,p3)
print("p",p2)
print("x",x2)
print("p",p3)
print("x",x3)
print("p",p3)
print("x",x4)
Based on this, My desired output is, (for 3 iterations)
p [0.1 0.8 2.7 6.4]
x [ 1. 4. 9. 16.]
p [1.000e-01 3.200e+00 2.430e+01 1.024e+02]
x [ 1. 4. 9. 16.]
p [1.000e-01 3.200e+00 2.430e+01 1.024e+02]
x [ 1. 4. 9. 16.]
Since the above code manually updating the values, I need to do the same thing using a for loop or some iterator in Python.
Since I am new to Python, I dont have a clue how to do that. Can anyone suggest an approach to do that?