must return a column vector

function dy=lodosact (t,y,So,V,Qo,U,Ks,Kd,Qr,Y,B)
global So V Qo U Ks B Kd Qr Y
V=17e6
Qr=0.65e10
Xo=100
Qo=2.08e6
B=4
So=200
Ks=100
U=0.5
Kd=0.0021
Y=0.6
dy(2)=(((So-y(2))./(V.*Qo))-((y(1).*y(2).*U)./(Y.*(Ks+y(2)))))
dy(1)=(((y(1)./(V.*Qo)).*((B.*(Qr.*Qo))-1-(Qr.*Qo))+((y(1).*y(2).*U)./((Ks+y(2))+(Kd.*y(1))))))
end
[t,y]= ode45('lodosact',[0 10],[100,200]);
plot (t,y)
title ('Actividad 20')
xlabel('T')
ylabel('ds/dx')
grid on
hold off

1 个评论

Moved from tags:
error using odearguments (line 93)
lodosact must return a column vector.
error in ode45 (line 115) odearguments(fcnhandlesused,solver_name,ode,tspan,y0,options,varargin)
error in correrlodosactivados (line 1)
[t,y]= ode45(@lodosact,[0 10],[100,200])

请先登录,再进行评论。

回答(2 个)

[t,y]= ode45(@lodosact,[0,2],[100,200]);
plot(t,y)
title('Actividad 20')
xlabel('T')
ylabel('ds/dx')
grid on
function dy=lodosact(t,y)
% no need for Global!!
V=17e6;
Qr=0.65e10;
Xo=100; % used nowhere
Qo=2.08e6;
B=4;
So=200;
Ks=100;
U=0.5;
Kd=0.0021;
Y=0.6;
dy = zeros(2,1); % have a look here
dy(1)=(((y(1)./(V.*Qo)).*((B.*(Qr.*Qo))-1-(Qr.*Qo))+((y(1).*y(2).*U)./((Ks+y(2))+(Kd.*y(1))))));
dy(2)=(((So-y(2))./(V.*Qo))-((y(1).*y(2).*U)./(Y.*(Ks+y(2)))));
end
When you use a single subscript to assign to an undefined variable, then MATLAB creates a row vector. For example,
xyz(2) = 42;
creates xyz as a 1 x 2 variable containing [0 42]
You assign to dy(2) and dy(1) without having initialized dy, so this rule applies, and you are creating dy as a 1 x 2 variable.
However, the output from an ode function must be a column vector.
Easiest fix is to assign to dy(2,1) and dy(1,1)

类别

帮助中心File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

产品

版本

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by