fallowing this question, I've solved the first two equations obtained dydt
as an array and wrote this code for the third one:
#some instants
g=1e-25
k=4.14*(10**-5)
#steps
steps=np.logspace(31.247237,33.35443,490000)
ini_values=[1/np.sqrt(2*k),0.7071067811865476]
def func(var,steps,dydt):
u=var[0]
dudt=var[1]
return [dudt,-((k**2)+(g*abs(dydt)/k))*u]
#make t and u have same dimension
u=np.empty_like(steps)
dudt=np.empty_like(steps)
#set initial values
u[0]=ini_values[0]
dudt[0]=ini_values[1]
this part solves the equation step-by-step; for example in step i
we use answers of step i-1
as new initial values.
for i in range(1,len(steps)):
#new steps
new_steps=[steps[i-1],steps[i]]
#solving equation
sol=odeint(func,ini_values,new_steps,args=(dydt[i],))
#saving data
u[i] = sol[1][0]
dudt[i] = sol[1][1]
# next initial condition
ini_values = sol[1]
but it takes too long time to get answer which is not efficient for me because I need to repeat this code like thousand times more, also I don't know even if that gives correct answer or not. Is this code correct? and if it is, is there any way to rewrite it to get answers faster?