coding error ode45

조회 수: 4 (최근 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 CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by