Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Solve Simultaneous Differential Equations

Subject: Solve Simultaneous Differential Equations

From: Chris Sorrento

Date: 5 Feb, 2012 13:50:09

Message: 1 of 3

I am trying to solve 3 differential equations simultaneously. But got the following error.

??? Undefined function or variable 'X'.

Error in ==> AGAPerfusion>Perfusion at 33
y(1) = Mu*X - kD*X + 9*X*y(2) - 10*X*y(2);

Error in ==> odearguments at 98
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 172
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in ==> AGAPerfusion at 19
[T, Y] = ode45(@Nested, [0 30], [X0; F0; CO20]);

I am wondering if the issue in my code below is due to improper notation. But I am stumped as to how to change the notation for X.

X0 = 1e5;
F0 = 1;
CO20 = 0.005;
Mu = 1.01;
kD = 0.2;
qGLC = 5.28e-13;
qCO2 = 5.36e-12;

[T, Y] = ode45(@Nested, [0 30], [X0; F0; CO20]);
plot(T,Y(:,1),'-sr',T,Y(:,2),'+b',T,Y(:,3),'og')
disp(Y)
% y(1) = dXdt
% y(2) = dF0dt
% y(3) = dCO2dt

% Nested Function
function dy = Nested(t,y)

dy = zeros(3,1);
y(1) = Mu*X - kD*X + 9*X*y(2) - 10*X*y(2);
y(2) = -qGLC*y(1);
y(3) = qCO2*y(1);
end

Subject: Solve Simultaneous Differential Equations

From: dpb

Date: 5 Feb, 2012 14:17:30

Message: 2 of 3

On 2/5/2012 7:50 AM, Chris Sorrento wrote:
> I am trying to solve 3 differential equations simultaneously. But got
> the following error.
>
> ??? Undefined function or variable 'X'.
>
> Error in ==> AGAPerfusion>Perfusion at 33
> y(1) = Mu*X - kD*X + 9*X*y(2) - 10*X*y(2);
>
> Error in ==> odearguments at 98
> f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
>
> Error in ==> ode45 at 172
> [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
>
> Error in ==> AGAPerfusion at 19
> [T, Y] = ode45(@Nested, [0 30], [X0; F0; CO20]);
>
> I am wondering if the issue in my code below is due to improper
> notation. But I am stumped as to how to change the notation for X.
...

> [T, Y] = ode45(@Nested, [0 30], [X0; F0; CO20]);
> plot(T,Y(:,1),'-sr',T,Y(:,2),'+b',T,Y(:,3),'og')
> disp(Y)
> % y(1) = dXdt % y(2) = dF0dt
> % y(3) = dCO2dt
>
> % Nested Function
> function dy = Nested(t,y)
>
> dy = zeros(3,1);
> y(1) = Mu*X - kD*X + 9*X*y(2) - 10*X*y(2);
> y(2) = -qGLC*y(1);
> y(3) = qCO2*y(1);
> end

[T,Y] = ODE45(ODEFUN,TSPAN,Y0,OPTIONS,P1,P2...) passes the additional
     parameters P1,P2,... to the ODE function as ODEFUN(T,Y,P1,P2...),
and to all functions specified in OPTIONS. Use OPTIONS = [] as a place
holder if no options are set.

You didn't pass X (nor the constants) as additional parameters as per
the documentation...hence they're unknown in the function.

--

Subject: Solve Simultaneous Differential Equations

From: Chris Sorrento

Date: 5 Feb, 2012 14:41:10

Message: 3 of 3

dpb <none@non.net> wrote in message <jgm31q$ffn$1@speranza.aioe.org>...
> On 2/5/2012 7:50 AM, Chris Sorrento wrote:
> > I am trying to solve 3 differential equations simultaneously. But got
> > the following error.
> >
> > ??? Undefined function or variable 'X'.
> >
> > Error in ==> AGAPerfusion>Perfusion at 33
> > y(1) = Mu*X - kD*X + 9*X*y(2) - 10*X*y(2);
> >
> > Error in ==> odearguments at 98
> > f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
> >
> > Error in ==> ode45 at 172
> > [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
> >
> > Error in ==> AGAPerfusion at 19
> > [T, Y] = ode45(@Nested, [0 30], [X0; F0; CO20]);
> >
> > I am wondering if the issue in my code below is due to improper
> > notation. But I am stumped as to how to change the notation for X.
> ...
>
> > [T, Y] = ode45(@Nested, [0 30], [X0; F0; CO20]);
> > plot(T,Y(:,1),'-sr',T,Y(:,2),'+b',T,Y(:,3),'og')
> > disp(Y)
> > % y(1) = dXdt % y(2) = dF0dt
> > % y(3) = dCO2dt
> >
> > % Nested Function
> > function dy = Nested(t,y)
> >
> > dy = zeros(3,1);
> > y(1) = Mu*X - kD*X + 9*X*y(2) - 10*X*y(2);
> > y(2) = -qGLC*y(1);
> > y(3) = qCO2*y(1);
> > end
>
> [T,Y] = ODE45(ODEFUN,TSPAN,Y0,OPTIONS,P1,P2...) passes the additional
> parameters P1,P2,... to the ODE function as ODEFUN(T,Y,P1,P2...),
> and to all functions specified in OPTIONS. Use OPTIONS = [] as a place
> holder if no options are set.
>
> You didn't pass X (nor the constants) as additional parameters as per
> the documentation...hence they're unknown in the function.
>

Thanks dbp for your response. I put [] as you suggested. Also, on the right hand side, I changed from y(1), y(2) y(3) to dy(1), dy(2) dy(3) and then replaced X with y(1). That solved the problem! Thanks again.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us