ODE迭代和循环
求解下列方程,在matlab中用ode45求解时,总是报错,不知道怎么回事?function dy=umodel(t,y,id,Y)
dy=zeros(2,1);
u=1.65; I=0.005; g=0.05; N=size(Y); N=N(1);
if id==1
J=g*(Y(id+1,1,:)-Y(id,1,:));
elseif id==N
J=g*(Y(id-1,1,:)-Y(id,1,:));
else
J=g*(Y(id+1,1,:)+Y(id-1,1,:)-2*Y(id,1,:));
end
dy(1)=-y(2)-u*(y(1).^2).*(y(1)-3/2)+I+J;
dy(2)=-y(2)+u*(y(1).^2);
迭代时用的语句
N=30; tspan=0:0.02:200;
Y=zeros(N,2,length(tspan)); T=zeros(N,length(tspan));
for i=1:30
= ode45(@(t,y) umodel(t,y,i,Y),tspan,);
T(i), Y(i,:)=y;
end
[ 本帖最后由 ChaChing 于 2009-5-5 14:16 编辑 ]
回复 楼主 chenwenjuan86 的帖子
matlab给的提示:??? In an assignmentA(:) = B, the number of elements in A and B
must be the same.
Error in ==> umodel at 19
dy(1)=-y(2)-u*(y(1).^2).*(y(1)-3/2)+I+J;
Error in ==> run>@(t,y)umodel(t,y,i,Y)
Error in ==> odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs,
odeFcn, ...
Error in ==> mymodel at 7
= ode45(@(t,y) umodel(t,y,i,Y),tspan,);
Error in ==> run at 57
evalin('caller', );
[ 本帖最后由 ChaChing 于 2009-5-5 14:19 编辑 ]
回复 沙发 chenwenjuan86 的帖子
:@( 有没有人帮忙看一下啊[ 本帖最后由 chenwenjuan86 于 2009-5-5 11:42 编辑 ]
回复 板凳 chenwenjuan86 的帖子
:@Q还是没有高人指点一下吗? 原帖由 chenwenjuan86 于 2009-4-28 10:36 发表 http://www.chinavib.com/forum/images/common/back.gif...??? In an assignmentA(:) = B, the number of elements in A and B
must be the same...
这个报错可参考
13F 常见的程序出错问题整理 (eight)
http://www.chinavib.com/forum/thread-46001-1-1.html
页:
[1]