如何使用 ODE45 函数求解这个三阶方程?
How can I solve this third order equation using the ODE45 function?
当我将三阶 ODE 转换为一阶 ODE 系统时,我得到了这个:
x1' = x2;
x2' = x3;
x3' = R1*x1+R2*x2-alpha*x3;
x4' = 1;
where
x4 = t;
R1 = -0.000001*(1-cos(theta*x4))-theta*sin(theta*x4)+1;
R2 = -(1-cos(theta*x4));
您需要创建一个文件,例如diffeq.m
function xdot = diffeq(t, x)
x4 = t;
R1 = -0.000001*(1-cos(theta*x4))-theta*sin(theta*x4)+1;
R2 = -(1-cos(theta*x4));
xdot(1) = x(2);
xdot(2) = x(3);
xdot(3) = R1*x(1)+R2*x(2)-alpha*x(3);
xdot = xdot'; % ODE solver expects a column vector.
然后使用 ODE45 语法调用它(来自此处:http://www.mathworks.com/help/matlab/ref/ode45.html?refresh=true)。
[t,x] = ode45(@diffeq, [tmin tmax], [x1_0, x2_0, x3_0, x4_0]);
当我将三阶 ODE 转换为一阶 ODE 系统时,我得到了这个:
x1' = x2;
x2' = x3;
x3' = R1*x1+R2*x2-alpha*x3;
x4' = 1;
where
x4 = t;
R1 = -0.000001*(1-cos(theta*x4))-theta*sin(theta*x4)+1;
R2 = -(1-cos(theta*x4));
您需要创建一个文件,例如diffeq.m
function xdot = diffeq(t, x)
x4 = t;
R1 = -0.000001*(1-cos(theta*x4))-theta*sin(theta*x4)+1;
R2 = -(1-cos(theta*x4));
xdot(1) = x(2);
xdot(2) = x(3);
xdot(3) = R1*x(1)+R2*x(2)-alpha*x(3);
xdot = xdot'; % ODE solver expects a column vector.
然后使用 ODE45 语法调用它(来自此处:http://www.mathworks.com/help/matlab/ref/ode45.html?refresh=true)。
[t,x] = ode45(@diffeq, [tmin tmax], [x1_0, x2_0, x3_0, x4_0]);