Hello, I am trying to solve these two coupled differential equations, but I can't seem to get it to work. I always have difficulty using ODE45...but why isn't the variable X being recognized? The image shows the differential equations I am trying to solve using MATLAB
alpha = 0.001; % L^-1
FA0 = 2.5; % mol/min
CA0 = 0.305; % mol/L
eps = 2;
k = 0.044;
CA = @(y,X) CA0*(1-X).*y./(1+eps*X);
rA = @(y,X) -k*CA(y,X);
vSpan = [0 500]; % L
dXdV = @(V,X) -rA(y,X)/FA0;
dydV = @(V,y) -alpha*(1+eps.*X)./(2*y);
[V, Y] = ode45(dydV,vSpan,1);
[V, X] = ode45(dXdV,vSpan,0);
But this is the error I encounter
Undefined function or variable 'X'.
Error in @(V,y)-alpha*(1+eps.*X)./(2*y)
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn,
...

 채택된 답변

Zoltán Csáti
Zoltán Csáti 2014년 11월 2일

0 개 추천

I found the mistake. It was a sign. :) The correct function is
function dz = myode(v,z)
alpha = 0.001;
C0 = 0.3;
esp = 2;
k = 0.044;
f0 = 2.5;
dz = zeros(2,1);
dz(1) = k*C0/f0*(1-z(1)).*z(2)./(1+esp*z(1));
dz(2) = -alpha*(1+esp*z(1))./(2*z(2));

댓글 수: 5

Rick
Rick 2014년 11월 2일
편집: Rick 2014년 11월 2일
so when doing coupled ODE's, then you want the variables in the same array, instead of trying to have two separate ode45 calls like I was doing at first? Where was I going wrong in my method?
Zoltán Csáti
Zoltán Csáti 2014년 11월 2일
In general, a coupled differential equation system can not be decoupled. So yes, all the dependent variables are put into a vector. Your method was wrong because you could not decouple the equations.
Rick
Rick 2014년 11월 2일
Thank you!
faiz islam
faiz islam 2016년 1월 24일
@Zoltan ,i tried it but where is "z" defined?i got error.can you share full code?
faiz
santosh kumar
santosh kumar 2017년 10월 5일
to define a function, use "syms function" example: to define x y z syntax: "syms x y z"

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

추가 답변 (2개)

Zoltán Csáti
Zoltán Csáti 2014년 11월 2일

0 개 추천

On line dydV = @(V,y) -alpha*(1+eps.*X)./(2*y); X is not included. I would solve it as a coupled system or solve it analytically by hand. I don't see the impact of C in the differential equations. Is C needed?

댓글 수: 1

Rick
Rick 2014년 11월 2일
the Concentration (CA) is needed for rA, which is in the dXdV differential equation

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

Zoltán Csáti
Zoltán Csáti 2014년 11월 2일

0 개 추천

Code your function as follows.
function dz = myode(v,z)
alpha = 0.001;
C0 = 0.3;
esp = 2;
k = 0.044;
f0 = 2.5;
dz = zeros(2,1);
dz(1) = k*C0/f0*(1-z(1)).*z(2)./(1-esp*z(1));
dz(2) = -alpha*(1+esp*z(1))./(2*z(2));
Then call it as
[v z] = ode45(@myode,[0 500],[0 1]);

댓글 수: 2

Rick
Rick 2014년 11월 2일
use plot(v,z) and you will see what the heck is going on with one of the functions. It is oscillating like crazy
Zoltán Csáti
Zoltán Csáti 2014년 11월 2일
Yes, I plotted it. It is very sensitive to the parameters. Try different parameter values.

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2014년 11월 2일

댓글:

2017년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by