matlab数值仿真

来源:百度知道 编辑:UC知道 时间:2024/05/29 09:52:47
程序为exp2_1.m ,帮我看看哪里不对啊

clear;clf; global c w
x0(1)=1;x0(2)=0;w=10;n=3;tspan=linspace(0,4,100);cc=[0.1 0.4 0.7 1];
xx=[];hold on,,xlabel('t'),ylabel('x'),
for i=1:length(cc);
c=cc(i);
[t,x]=ode45('exp2_1f ',tspan,x0); %求微分方程的数值解。
xx=[x(:,1),xx];
text(t(10),x(10,1),['\leftarrow c=',num2str(c)],'fontsize',15)
plot(t,x(:,1)),
end

exp2_1f.m 是 od45指令中的微分方程组函数子程序
function dx=exp2_1f(t,x)
global c w
u=0;dx=zeros(2,1);
dx(1)=x(2);dx(2)=u-c*w*x(2)-w^2*x(1);

clear;clf; global c w
x0(1)=1;x0(2)=0;w=10;n=3;tspan=linspace(0,4,100);cc=[0.1 0.4 0.7 1];
xx=[];hold on;xlabel('t'),ylabel('x'),
for i=1:length(cc);
c=cc(i);
[t,x]=ode45('exp2_1f',tspan,x0); %求微分方程的数值解。
xx=[x(:,1),xx];
text(t(10),x(10,1),['\leftarrow c=',num2str(c)],'fontsize',15)
plot(t,x(:,1)),
end

来自:求助得到的回答