早教吧 育儿知识 作业答案 考试题库 百科 知识分享

matlab 程序出错,帮我看看错在哪儿了函数function dvdt=huxi(t,v) global W L A po pc pn t v P0 P xo xc xn ro rcdvdt=[A/L*po*(xo*P0/100-v(1)/(v(1)+v(2)+v(3)+v(4))*P)-ro*W;A/L*pc*(xc*P0/100-v(2)/(v(1)+v(2)+v(3)+v(4))*P)+rc*W;A/L*pn*(xn*P0/10

题目详情
matlab 程序出错,帮我看看错在哪儿了
函数
function dvdt=huxi(t,v)
global W L A po pc pn t v P0 P xo xc xn ro rc
dvdt=[
A/L*po*(xo*P0/100-v(1)/(v(1)+v(2)+v(3)+v(4))*P)-ro*W;
A/L*pc*(xc*P0/100-v(2)/(v(1)+v(2)+v(3)+v(4))*P)+rc*W;
A/L*pn*(xn*P0/100-v(3)/(v(1)+v(2)+v(3)+v(4))*P);
0
];
运行
t_start=0;
t_end=1;
vv0=[yo0*V/100;yc0*V/100;yn0*V/100;ye0*V/100];
for ro=romin:0.1:romax
for rc=rcmin:0.1:rcmax
[t,v]=ode45('huxi',[t_start,t_end],vv0);
yo=v(end,1)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
yc=v(end,2)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
yn=v(end,3)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
if yo(1)==yoend/100 & yc(1)==ycend/100
break
ro
rc
end
end
end
说明
其中的参数如W,A,L,po,pc,pn,V,yo0,yc0,yn0,romax,romin,rcmax,rcmin,yoend,ycend等,已经在前面通过输入赋值了.
出错
Error using ==> funfun\private\odearguments
Solving HUXI requires an initial condition vector of length 2.
Error in ==> ode45 at 173
[neq,tspan,ntspan,next,t0,tfinal,tdir,y0,f0,odeArgs,odeFcn,...
%把程序补充完整了
function dvdt=huxi(t,v)
global W L A po pc pn P0 P xo xc xn ro rc;
dvdt=zeros(4,1);
dvdt=[
A/L*po*(xo*P0/100-v(1)/(v(1)+v(2)+v(3)+v(4))*P)-ro*W;
A/L*pc*(xc*P0/100-v(2)/(v(1)+v(2)+v(3)+v(4))*P)+rc*W;
A/L*pn*(xn*P0/100-v(3)/(v(1)+v(2)+v(3)+v(4))*P);
0];
%运行
W=0.106;L=0.012/1000;A=600/10000;V=500;
po=0.032498;pc=0.044255;pn=0.03837;
yo0=20.9;yc0=0.03;yn0=78.08;ye0=100-yo0-yc0-yn0;
romax=190;romin=150;rcmax=190;rcmin=150;
yoend=17.6;ycend=3.4;
xo=20.95;xc=0.03;xn=78.08;P0=101000;P=101000;
t_start=0;
t_end=1;
vv0=[yo0*V/100;yc0*V/100;yn0*V/100;ye0*V/100]; %初值
for ro=romin:0.1:romax
for rc=rcmin:0.1:rcmax
[t,v]=ode45('huxi',[t_start,t_end],vv0);
yo=v(end,1)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
yc=v(end,2)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
yn=v(end,3)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
if yo(1)==yoend/100 & yc(1)==ycend/100
ro
rc
end
end
end
▼优质解答
答案和解析
问题所在:
Solving HUXI requires an initial condition vector of length 2.
初始条件长度为2,这儿有问题,(实际应该是4吧)
只能说明函数的定义不满足条件
改一下函数定义:
function dvdt=huxi(t,v)
global W L A po pc pn P0 P xo xc xn ro rc %去掉t v ,但应该不是主要问题
dvdt=zeros(4,1);%主要是检测函数有用
dvdt=[
A/L*po*(xo*P0/100-v(1)/(v(1)+v(2)+v(3)+v(4))*P)-ro*W;
A/L*pc*(xc*P0/100-v(2)/(v(1)+v(2)+v(3)+v(4))*P)+rc*W;
A/L*pn*(xn*P0/100-v(3)/(v(1)+v(2)+v(3)+v(4))*P);
0];
从你给的信息只能看到这些了,如果还有问题,信息再详细点
直接拷贝下面代码也可以运行
function solFOUND
global W L A po pc pn P0 P xo xc xn ro rc;
W=0.106;L=0.012/1000;A=600/10000;V=500;
po=0.032498;pc=0.044255;pn=0.03837;
yo0=20.9;yc0=0.03;yn0=78.08;ye0=100-yo0-yc0-yn0;
yoend=17.6;ycend=3.4;
xo=20.95;xc=0.03;xn=78.08;P0=101000;P=101000;
romax=190;romin=150;rcmax=190;rcmin=150;
t_start=0;
t_end=1;
vv0=[yo0*V/100;yc0*V/100;yn0*V/100;ye0*V/100]; %初值
for ro=romin %改回原来的
for rc=rcmin %改回原来的
[t,v]=ode45(@huxi,[t_start,t_end],vv0);
yo=v(end,1)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
yc=v(end,2)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
yn=v(end,3)/(v(end,1)+v(end,2)+v(end,3)+v(end,4));
if yo(1)==yoend/100 & yc(1)==ycend/100
ro
rc
end
end
end
function dvdt=huxi(t,v)
global W L A po pc pn P0 P xo xc xn ro rc;
dvdt=zeros(4,1);
dvdt=[
A/L*po*(xo*P0/100-v(1)/(v(1)+v(2)+v(3)+v(4))*P)-ro*W;
A/L*pc*(xc*P0/100-v(2)/(v(1)+v(2)+v(3)+v(4))*P)+rc*W;
A/L*pn*(xn*P0/100-v(3)/(v(1)+v(2)+v(3)+v(4))*P);
0];