matlab ode45

fun.m  文件里面定义微分方程组

function dx = fun(t, x)

dx = zeros(2, 1);

dx(1) = -x(1).^3 - x(2);

dx(2) = x(1) - x(2).^3;

end

运行命令:

[t,x] = ode45(@fun, [0,30], [1;0.5]);

[0, 30] 是 t 的区间,[1; 0.5] 是初值。

得到:一列 t, 两列 x。

精度参数:

options = odeset('RelTol', 1e-4, 'AbsTol', [1e-4, 1e-5]);

x(1), x(2) 的总的相对误差(relative error)是 1e-4,绝对误差(absolute error)分别是1e-4, 1e-5。

[t,x] = ode45(@fun, [0,30], [1;0.5], options);

猜你喜欢

转载自blog.csdn.net/beifangyu/article/details/82315686
今日推荐