MATLAB Answers

ODE solving lack of span inputs

조회 수: 2(최근 30일)
Oliver Massaad
Oliver Massaad 2020년 11월 23일
편집: Bjorn Gustavsson 2020년 11월 23일
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];
%Solving for the differential equation for the volume
%Since written in terms of concentration of A, extraxt last value (at time
%t) of the first column
%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
%Defining rate laws
%Assigning the rates of change of each compound to the output
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
  댓글 수: 2
Oliver Massaad
Oliver Massaad 2020년 11월 23일
Where at time 0 ca=0 and the tspan from 0 to 168169 s

댓글을 달려면 로그인하십시오.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 11월 23일
편집: Bjorn Gustavsson 2020년 11월 23일
OK, you have 2 coupled ODEs. If I expand the D/Dt(log(V(t))) to 1/V(t)*D/Dt(V(t) I'd get something like this:
function dVdtdcadt = odeperhaps(Vca,t)
k = 12; % perhaps some correction...
V = Vca(1);
ca = Vca(2);
dcadt = k*ca^2;
dVdt = -k*ca*V - dcadt*V/ca;
dVdtdcadt = [dVdt;dcadt];
These coupled ODEs you then integrate together. You might want to set the ode-options that ensure the solutions are kept positive - check the help and documentation for ode45 and odeset, it should be the 'NonNegative' field that should be used. That ought to make the V and ca in the denominators safe...
Perhaps I misstyped something.

추가 답변(1개)

Bjorn Gustavsson
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.
  댓글 수: 2
Bjorn Gustavsson
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?

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by