Solving 2 ODE's with ode45

29 ビュー (過去 30 日間)
Tarek Chahattou
Tarek Chahattou 2019 年 10 月 23 日
回答済み: Stephan 2019 年 10 月 23 日
New Doc 2019-10-22 22.24.58_1.jpg
Im trying to solve these 2 differential equations like this:
tfinal = 100;
t = linspace(0,tfinal,100);
winitial = [1 300];
[T, Ca] = ode45(@sub1,t,winitial)
plot(t,Ca)
%%%%%%%%% Subfunction
function d_dt = sub1(Ca,T)
d_dt = zeros(2, 1);
d_dt(1,1) = -0.1*Ca*exp(-300/T);
d_dt(2,1) = 1*Ca*exp(-300/T);
end
but i keep getting these errors. Does it have something to do with the subfunction? I was having trouble with it
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2.
Error in explicit_Eu_hw>sub1 (line 28)
d_dt(1,1) = -0.1*Ca*exp(-300/T);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in explicit_Eu_hw (line 20)
[T, Ca] = ode45(@sub1,t,winitial)

採用された回答

Stephan
Stephan 2019 年 10 月 23 日
tfinal = 100;
tspan = [0 tfinal];
winitial = [1 300];
[t,y] = ode45(@sub1,tspan,winitial)
plot(t,y,'LineWidth',2)
%%%%%%%%%Subfunction
function d_dt = sub1(t,y)
Ca = y(1);
T=y(2);
d_dt = zeros(2, 1);
d_dt(1,1) = -0.1*Ca*exp(-300/T);
d_dt(2,1) = 1*Ca*exp(-300/T);
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by