I'm trying to solve three ode, one of them is first order and others are second order ode. here are the equations:
and here is the code:
#note that:
p[0]=y
p[1]=dy/dt
p[2]=q
p[3]=u
p[4]=du/dt
#initial values and requirements :
import numpy as np
import time
from scipy.integrate import odeint
g=1e-25
k=4.14*(10**-5)
t=(10**31)*np.logspace(0.247237,2.35443,10**7)
t=t.tolist()
z0=[2.435*1e26,0,1/3400]
#equations:
def my_eqs1(p,t):
return[p[1],-2*p[2]*1.4441*(10**-33)*np.sqrt(0.31*(p[2]**-4)*(p[2]+1/3400)+0.69)*p[1]-
(r*p[2])**(2)*p[0],p[2]*p[2]*1.4441*(10**-33)*np.sqrt(0.31*(p[2]**-4)*(p[2]+1/3400)+0.69)]
#solving:
start_time=time.perf_counter()
r=1e-29
z1=odeint(my_eqs1,z0,t)
end_time=time.perf_counter()
print(end_time-start_time,"seconds")
In the next step, I have to use p[1]
to solve another second order ode, so I tried to redefine my_eqs1
as fallows to solve all of them simultaneously:
def my_eqs2(p,t):
return[p[1],-2*p[2]*1.4441*(10**-2)*np.sqrt(0.31*(p[2]**-4)*(p[2]+1/3400)+0.69)*p[1]-
((1e31*r*p[2])**2)*p[0],p[2]*p[2]*1.4441*(10**-2)*np.sqrt(0.31*(p[2]**-4)*(p[2]+1/3400)+0.69)
,1e-62*p[4],-((k**2)+(g*p[1]/k))*p[3]]
and new z0
:
z0=[2.435*1e26,0,1/3400,1/np.sqrt(2*k),0.35927359523]
But this time odeint
gives this answer which is not good at all.
What is wrong with this code?
By redefining functions and scaling t
, (as t->1e31*t) I've got some answers:
t=np.logspace(0.247237,2.35443,10**7)
def my_eqs3(p,t):
return[p[1],-2*p[2]*1.4441*(10**-2)*np.sqrt(0.31*(p[2]**-4)*(p[2]+1/3400)+0.69)*p[1]-
((1e31*r*p[2])**2)*p[0],p[2]*p[2]*1.4441*(10**-2)*np.sqrt(0.31*(p[2]**-4)*(p[2]+1/3400)+0.69)
,1e-62*p[4],-((k**2)+(g*p[1]/k))*p[3]]