簡體   English   中英

Python中的三階微分方程

[英]Third order differential equation in python

我是Python的新手,所以目前我只能解決一些非常基本的問題。

如何在Python中解決這樣的ODE?

在此處輸入圖片說明

https://docs.scipy.org/doc/scipy-0.18.1/reference/generation/scipy.integrate.ode.html

這里是您要搜索的庫,如果您向下滾動底部,也有一些示例。 閱讀愉快

您的解決方案可能看起來像這樣(如果刪除所有與繪圖相關的線,則該長度很短)

import numpy as np
from scipy.integrate import odeint
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as pl

# define the ODE as a first order system
def func(y,x):
    return [ 
        y[1], 
        y[2], 
        ( 7*x**1.5 - 5*x**2*y[2]-2*x*y[1] + 2*y[0]) / x**3 
        ]    

# initial values
y0=[ 10.6, -3.6, 31.2]
# points at which the solution value is requested
x = np.linspace(1,10,501)
# numerical integration
y=odeint(func, y0, x)
# y[-1,:] contains the value at x=10
print "[ y(10), y'(10), y''(10) ] = ", y[-1,:]

# plot the solution with subplots for each component
fig=pl.figure()
ax=fig.add_subplot(311)
ax.plot(x, y[:,0])
ax=fig.add_subplot(312)
ax.plot(x, y[:,1])
ax=fig.add_subplot(313)
ax.plot(x, y[:,2])
pl.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM