如何使用函数及其导数(' s)在Python中求解另一个微分方程?
我需要在Python中同时解决这两个方程式: “ B”是恒定的;但是我不知道如何将函数“ P”及其导数放在第二个方程式中, 有人可以帮助我吗?
版: 我已经写了此代码来解决这个问题,但我不知道它是正确的。此代码是否正确给出了这些方程式的答案?
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import scipy.integrate as sy
import sys
import numpy as np
np.set_printoptions(threshold=sys.maxsize)
import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
b=2
def eq(t,u):
#u[0] is p and u[1] is p', u[2]=y, u[3]=y'.
u[1]=u[0]*np.sqrt(0.25*(u[0]**-4)*(u[0]+(1/7)+0.7)
return [u[0],u[1],u[3],-3*(u[1]/(b*u[0]))*u[3] - u[2]]
u0 = [0.00001,0.00001,1.22*(10**28),0]
t = np.linspace(0.0000000001,0.6924*10**33,10000)
sol=solve_ivp(eq,t,u0,None)
I need to solve this two equations simultaneously in python :
"b" is constant; but I don't know how to put the function "P" and its derivative at same time in the second equations code,
is there anyone could help me?
edition:
I have wrote this code to solve the question, but I don't know it is correct or not. is this code correctly gives the answer of those equations?
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
import scipy.integrate as sy
import sys
import numpy as np
np.set_printoptions(threshold=sys.maxsize)
import numpy as np
from scipy.integrate import solve_ivp
import matplotlib.pyplot as plt
b=2
def eq(t,u):
#u[0] is p and u[1] is p', u[2]=y, u[3]=y'.
u[1]=u[0]*np.sqrt(0.25*(u[0]**-4)*(u[0]+(1/7)+0.7)
return [u[0],u[1],u[3],-3*(u[1]/(b*u[0]))*u[3] - u[2]]
u0 = [0.00001,0.00001,1.22*(10**28),0]
t = np.linspace(0.0000000001,0.6924*10**33,10000)
sol=solve_ivp(eq,t,u0,None)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论