matlab解微分代数方程,哪里出错了?function xdot=swing(t,x)xdot=[x(2); -0.5*x(1); x(4); -0.5*x(3)-9.81; x(1)^2+x(3)^2-1];----------------------------->>M= diag([1 1 1 1 0]);>> option=odeset;option.Mass=M;>> x0=[0.5;0;sqrt(1-0.

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/08 14:42:15

matlab解微分代数方程,哪里出错了?function xdot=swing(t,x)xdot=[x(2); -0.5*x(1); x(4); -0.5*x(3)-9.81; x(1)^2+x(3)^2-1];----------------------------->>M= diag([1 1 1 1 0]);>> option=odeset;option.Mass=M;>> x0=[0.5;0;sqrt(1-0.
matlab解微分代数方程,哪里出错了?
function xdot=swing(t,x)
xdot=[x(2);
-0.5*x(1);
x(4);
-0.5*x(3)-9.81;
x(1)^2+x(3)^2-1];
-----------------------------
>>M= diag([1 1 1 1 0]);
>> option=odeset;option.Mass=M;
>> x0=[0.5;0;sqrt(1-0.5^2);0];
>> [t,x]=ode15s(@swing,[0,20],x0,option)
? Error using ==> odearguments at 116
Solving SWING requires an initial condition vector of length 4.
Error in ==> ode15s at 228
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

matlab解微分代数方程,哪里出错了?function xdot=swing(t,x)xdot=[x(2); -0.5*x(1); x(4); -0.5*x(3)-9.81; x(1)^2+x(3)^2-1];----------------------------->>M= diag([1 1 1 1 0]);>> option=odeset;option.Mass=M;>> x0=[0.5;0;sqrt(1-0.
close all
clear,clc
swing=@(t,x)[x(2);
-0.5*x(1);
x(4);
-0.5*x(3)-9.81];
x0=[0.5;0;sqrt(1-0.5^2);0];
s=ode15s(swing,[0,20],x0);
plot(s.x,s.y);legend('x(1)','x(2)','x(3)','x(4)')
你不觉得四个函数四个方程已经够了么?
你在给他多一个约束,怎么解?
你可以检验下
x(:,1).^2+x(:,3).^2
根本不会恒等于1的

为啥错了啊?我也遇到这个问题了。。求助啊