coding error ode45

1 view (last 30 days)
Sarah Bhuyian
Sarah Bhuyian on 10 Nov 2019
Edited: Stephan on 10 Nov 2019
clc;
close all;
global a b a2
%define parameters
%x is the number of cancer cells
x0 = 1000;
% c2 is the number of bad stromal cells
c20 = 30;
%b is the number of bad stroma cells (ratio)
b = 20;
% a is the growth rate of cancer cells
a = 0.35;
% a2 growth rate of cancerous stroma
a2 = 0.4;
%time parameter (measured in weeks)
t0=0; %initital time
t1=520; %final time
tspan=t0:1:t1;
[t, x] = ode45('badstromarun',tspan,x0);
figure(1)
plot(t,x)
Recall file
function xdot= badstromarun(t,x)
global a b
xdot = zeros(1,1);
xdot = (a*x)*(1-log(x)/b)*(c2/(a2+c2));
end
A lot of erros keep occuring
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in badstroma (line 29)
[t, x] = ode45('badstromarun',tspan,x0);

Accepted Answer

Stephan
Stephan on 10 Nov 2019
Edited: Stephan on 10 Nov 2019
If possible try to avoid global variables:
%define parameters
%x is the number of cancer cells
x0 = 1000;
% c2 is the number of bad stromal cells
c2 = 30;
%b is the number of bad stroma cells (ratio)
b = 20;
% a is the growth rate of cancer cells
a = 0.35;
% a2 growth rate of cancerous stroma
a2 = 0.4;
%time parameter (measured in weeks)
t0=0; %initital time
t1=520; %final time
tspan=[t0 t1];
% plot result
[t, x] = ode45(@(t,x)badstromarun(t,x,a2,a,b,c2),tspan,x0);
figure(1)
plot(t,x)
% function
function xdot= badstromarun(~,x,a2,a,b,c2)
xdot = zeros(1,1);
xdot(1) = (a.*x).*(1-log(x)/b)*(c2/(a2+c2));
end

More Answers (0)

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!