用Eu求解多方程常微分方程

2024-05-29 02:46:19 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,如果这是一个noob问题,我很抱歉,我对编码是新手。我试图用欧拉方法解这个方程:

enter image description here

我们可以这样解决它(来自一个示例):

def ODE_Euler(ic, h, endpoint, f):
    n = int((1/0.1) + 1)
    x = np.linspace(start=0, stop=1, num=n)
    y = np.zeros(n)

    y[0] = ic # initial condition
    for i in range(10):
        y[i+1] = y[i] + h*f(x[i], y[i])

    return x, y

def dydx(x, y):
    return #the equation

x, y = ODE_Euler(1.0, 0.1, 1, dydx)
import pandas as pd
result = pd.DataFrame({
    "x":x,
    "y":y
})
result

有人能帮忙吗


Tags: 方法编码returndefnpresultpdode

热门问题