ODE solving lack of span inputs
古いコメントを表示
I have this piece of code and I dont know what is the problem, it says the tspan argument must have at least two arguments.
%Initial conditions
tspan=[0, 168169];
c0=[0.5,0,0];
%Solving for the differential equation for the volume
[t,lnV]=ode45(@cstP_V,tspan,c0);
%Since written in terms of concentration of A, extraxt last value (at time
%t) of the first column
V=exp(lnV(end,1))
%Function is defined
function dlnV=cstP_V(t,C) %Time and initial concentration constants
k=0.0023; %Reaction rate constant
function dC=cstP_C(t,C) %Embeded function determining the rate of change of concentration of compounds
%Assigning inital concentrations
CA=C(1);
CB=C(2);
CC=C(3);
%Defining rate laws
r=k*CA^2;
CA=-r;
CB=r;
CC=r;
%Assigning the rates of change of each compound to the output
dC(1,:)=CA;
dC(2,:)=CB;
dC(3,:)=CC;
end
dCA=cstP_C(t,C); %obtaining rate of change in concentration with initial conditions from main function
[~,C1]=ode45(@cstP_C,[0 1],C); %solving for concentration values (tspan values had to be respecified for after already calling function)
ca=C1(end,1); %determining ca at time t
dlnV=-1*(ca^(-1)*dCA+(k*ca)); %specifying the rate of change in ln(V) from derived relation
end
2 件のコメント
Steven Lord
2020 年 11 月 23 日
Can you show us the mathematical form of the system of ODEs that you're trying to solve? I'm not sure exactly what you're trying to solve based on the code you've posted.
HWIK
2020 年 11 月 23 日
採用された回答
その他の回答 (1 件)
Bjorn Gustavsson
2020 年 11 月 23 日
The error is most likely in the second ode45-call. In that subfunction the time t will always be a scalar. You might want to change that to:
[~,C1]=ode45(@cstP_C,[0 t],C);
But that also looks peculiar to me.
HTH
2 件のコメント
HWIK
2020 年 11 月 23 日
Bjorn Gustavsson
2020 年 11 月 23 日
I'll have to repeat the recommendation of Steven, you might get better help if you show us your ODE-system in mathematical form. The "inner" ODE you use has the fragrance of something "being a bit off" - maybe that equation should be coupled to the others in a more direct way?
カテゴリ
ヘルプ センター および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!