作业帮 > 数学 > 作业

matlab解微分代数方程,哪里出错了?

来源:学生作业帮 编辑:作业帮 分类:数学作业 时间:2024/07/08 03:07:39
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, ...
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的
再问: 约束是有的 原题是薛定宇《基于matlab/simulink的系统仿真技术与应用》P190第14题: 一个单摆方程组: x'' = -0.5x y'' = -0.5y-9.81 x^2+y^2-1=0 初值:x(0)=0.5,y(0)=sqrt(1-0.5^2),x'(0)=y'(0)=0 应该怎么解?