MATLAB Answers

0

coding error ode45

Asked by Sarah Bhuyian on 10 Nov 2019 at 13:04
Latest activity Edited by Stephan
on 10 Nov 2019 at 13:35
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);

  0 Comments

Sign in to comment.

1 Answer

Stephan
Answer by Stephan
on 10 Nov 2019 at 13:30
Edited by Stephan
on 10 Nov 2019 at 13:35
 Accepted Answer

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

  0 Comments

Sign in to comment.