这种简单错误自己看看基础书籍就能发现的, 希望以后能自己多思考:
%%% 将以下代码存为changpingpin.m,再运行即可
%%%%%%%%%%%%%%%%%%%%%%%%
function changpingpin
u0=[-1;-3;-2;1;2;3]; tspan=[0 20]; [t,u]=ode45(@changode,tspan,u0);
plot(t,u(:,1),t,u(:,2),t,u(:,3)); legend('u(1)','u(2)','u(3)'); xlabel('t'); ylabel('u');
function dudt=changode(t,u)
dudt=zeros(6,1); dudt(1)=u(4); dudt(2)=u(5); dudt(3)=u(6);
dudt(4)=-2*u(1)-u(2)-u(4)+3*sin(t);
dudt(5)=0.5*u(1)-u(2)+0.5*u(4)-0.5*u(6)+sin(t);
dudt(6)=(1/3)*(-4*u(3)-u(5))+2*sin(t);
%%%%%%%%%%%%%%%%%%%%%%%%
[ 本帖最后由 ChaChing 于 2010-6-28 18:43 编辑 ] |