coding error ode45

4 vues (au cours des 30 derniers jours)
Sarah Bhuyian
Sarah Bhuyian le 10 Nov 2019
Modifié(e) : Stephan le 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);

Réponse acceptée

Stephan
Stephan le 10 Nov 2019
Modifié(e) : Stephan le 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

Plus de réponses (0)

Catégories

En savoir plus sur Dialog Boxes dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by