coding error ode45

1 回表示 (過去 30 日間)
Sarah Bhuyian
Sarah Bhuyian 2019 年 11 月 10 日
編集済み: Stephan 2019 年 11 月 10 日
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);

採用された回答

Stephan
Stephan 2019 年 11 月 10 日
編集済み: Stephan 2019 年 11 月 10 日
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 件)

カテゴリ

Help Center および File ExchangeDialog Boxes についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by