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:
problem using ode45

Subject: problem using ode45

From: nur munajat

Date: 14 Sep, 2009 09:57:02

Message: 1 of 2

Hi,
i've this m.file
function [t x] = CA1part1
clear all
clc
%
global k T Fbo Nao rA V Vo vo ke txlinear txspline
% constant
T = 300;
ke = 1.08;
k = 9e-5;
Vo = 200;
vo = 0.05;
Cao = 7.72;
Cbo = 10.93;
% data and start avlue for x
x0 = 0.05;
% time span
tspan = [0 500];
%
options = odeset ('Events',@g);
[t x] = ode45(@f,tspan,x0,options);
%
Ca = Nao(1-x)/V;
Cb = (Fbo*t-Nao*x)/V;
Cc = Nao*x/V;
Cd = Nao*x/V;
rA = -k*(Ca*Cb-Cd*Cc/ke);
Nao = Cao*Vo;
V = Vo + vo*t;
Fbo = Cbo*vo;
%
plot (t,x);
% find time for X = 0.10, 0.75
txlinear = interp1(x,t,[0.10;0.75],'linear');
txspline = interp1(x,t,[0.10;0.75],'spline');
%
function dxdt = f(t,x)
global k T Fbo Nao rA V Vo vo ke txlinear txspline
dxdt = (k*Nao/(Vo+vo*t))*((1-x)*(Fbo*t/Nao-x)-x^2/ke);
%
function [val,isterm, dir] = g(t,x)
global k T Fbo Nao rA V Vo vo ke txlinear txspline
val = x-1.0;
isterm = 1;
dir = 0;

but i got this error when i try to run it,

??? Error using ==> funfun\private\odearguments
Solving F requires an initial condition vector of length 1.

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

Error in ==> CA1part1 at 22
[t x] = ode45(@f,tspan,x0,options);

Really need someone to help me
Regards,
Nur

Subject: problem using ode45

From: Eric

Date: 14 Sep, 2009 12:08:01

Message: 2 of 2

Within the function "f" the global variables "Fbo" and "Nao" are used, but in the main-function a value is assigned to those variables only in the code section below the call to ode45. Therefore "Fbo" and "Nao" contain an empty matrix and the function f returns an empty matrix when called by ode45.

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