我重新做了一下
1建了一个矩阵函数
function A=mass(t,y,Da,Dm,E) %% t,y 都没有用到
A=zeros(4,4);
A(1,1)=-Da.*E;
A(1,4)=Dm/0.8738;
A(2,1)=Da/0.001025.*E;
A(2,2)=-(Da*0.01+0.0398)/0.001025;
A(2,3)=-Da/0.001025;
A(3,2)=1/2.896;
A(3,3)=-1/(0.8738.*2.896);
A(3,4)=1/(0.8738.*2.896);
A(4,1)=Dm*E/4;
A(4,3)=-1/(0.8738*4);
保存为mass.a %%为什么是*.a格式
2 微分方程
function dydt=massode(t,y,Da,Dm,E) %% 所有变量都没用到,参数没法传过来
dydt=[ A(1,1)*y(1)+A(1,4)*y(4)
A(2,1)*y(1)+A(2,2)*y(2)+A(2,3)*y(3)
A(3,2)*y(2)+A(3,3)*y(3)+A(3,4)*y(4)
A(4,1)*y(1)+A(4,3)*y(3) ];
3 主程序
t=0:0.008:2;
tn=t./(0.2+0.1555*0.8);
En=1.553174.*(tn./0.7).^1.9./(1+(tn./0.7).^1.9)./(1+(tn./1.173474).^21.9);
Ea=En.*3.0;
E=Ea+0.06;
Vl=69.36;
Qa=0;
Pa=90;
Pr=5;
if Pr>Pa
Dm=0;
Da=1;
else
Dm=1;
Da=0;
tspan=[0 2];
y0=[69.36;0;90;5];
options=odeset('Mass','@mass');
[t,y]=ode45(@odemass,tspan,y0,options,Da,Dm,E);%% 上面是massode,这里是odemass
end
plot(t,y(:,1))
运行后
??? Undefined function or variable 'A'.
Error in ==> D:\program\matlab65\work\odemass.m
On line 2 ==> dydt=[ A(1,1)*y(1)+A(1,4)*y(4)
Error in ==> D:\program\matlab65\toolbox\matlab\funfun\private\odearguments.m
On line 104 ==> f0 = feval(ode,t0,y0,args{:});
Error in ==> D:\program\matlab65\toolbox\matlab\funfun\ode45.m
On line 155 ==> [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, args, ...
[ 本帖最后由 sigma665 于 2007-12-28 13:10 编辑 ] |