From: jin on
clc clear
function xdot=Fogler49(t,x)

% Example 4.9 pg220-223
%x(1)=ca
%x(2)=cb
%x(3)=cc
%x(4)=cd
%xdot(1)=d(ca)/dt, xdot(2)=d(cb)/dt, xdot(3)=d(cc)/dt, xdot(40=d(cd)/dt


v0=5;
v00=0.05;
v=v0+v00*t;
k=2.2;
cb0=0.025;
rate=k*x(1)*x(2);
ca0=0.05;

xdot(1,:)=-k*x(1)*x(2)-v00*x(1)/v;
xdot(2,:)=-k*x(1)*x(2)+v00*(cb0-x(2))/v;
xdot(3,:)=k*x(1)*x(2)-v00*x(3)/v;
xdot(4,:)=k*x(1)*x(2)-v00*x(4)/v;

ic=[0.05;0;0;0];tspan=[0;500];
[t,x]=ode45('Fogler49',tspan,ic);

plot(t,x);
title('Example 4-9');
xlabel('time(sec)');
ylabel('ca,cb,cc,cd');

i don't know how to fix the problem
i am getting an error called "Function definitions are not permitted at the prompt or in scripts."
please help me out thank you
From: Matt Fig on
Erase that silly first line in your file.

Since a function has its own workspace, there is no need to clear at the beginning (especially if arguments are passed!), however you can put CLC as the first line *after* the function definition if you so desire. Also, see the HOME function.
From: ImageAnalyst on
To expand on Matt's explanation, the clear statement was the script.
Then you had a function definition below that. MATLAB does not allow
that. It does not allow a script to be followed by a function. If
you had two functions, that would be fine, but not a script and a
function. For example, let's say this code was saved in an m-file
called "test.m." Then you could do this and it would be OK because
there are two functions:

function test()
clc;
% Any other code you want to want to run in test()
return; % from test()

function xdot = Fogler49(t, x)
% Here is the code for Fogler49()
return; % from Fogler49