ODE error and vector error
12 views (last 30 days)
Show older comments
Error in my code:
Error using odearguments (line 95)
@(T,X)BADSTROMARUN(T,X,A,A1,A2,B,B1,B2,B3,C1,C2,D1,D2) returns a vector of length 2, but the length of initial conditions
vector is 4. The vector returned by @(T,X)BADSTROMARUN(T,X,A,A1,A2,B,B1,B2,B3,C1,C2,D1,D2) and the initial conditions vector
must have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in badstroma (line 37)
[t, x] = ode45(@(t,x)badstromarun(t,x,a,a1,a2,b,b1,b2,b3,c1,c2,d1,d2),tspan,X0);
Unsure what this means but I have tried multiple different ways to try and code my plots of cell growth
clc;
close all;
%define parameters
%x is the number of cancer cells
C0 = 100;
% c2 is the number of bad stromal cells
S0 = 100;
s1=C0/(C0+S0);
s2=S0/(C0+S0);
X0=[C0;S0;s1;s2];
% a, b is the growth rate of cancer cells
a = 0.35;
b = 0.35;
% a1 a2 growth rate of cancerous stroma
a1 = 0.01; %intrinsic growth
a2 = 0.01; %growth due to stroma
b1 = 0.1; % influence of bad stroma delay
b2 = 0.1; %stroma inheremnt prolifiration
b3 = 0.01; % strome slow-down prolifiration rate due to large number of stroma cells
c1=0.001; % dies naturally and due to C/S factor
d1=0.05; % natural death of stromA
c2=0.2; % dies due to stravation
d2=0.2; % dies due to stravation
%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,a,a1,a2,b,b1,b2,b3,c1,c2,d1,d2),tspan,X0);
figure(1)
plot(t,real(x(:,1)))
figure(2)
plot(t,real(x(:,2)))
function xdot= badstromarun(~,x,a,a1,a2,b,b1,b2,b3,c1,c2,d1,d2)
xdot = zeros(2,1);
%xdot(1) = (a1+a2*(x(2)/(b1+x(2))))*x(1)*(1-log(x(1))/a)-x(1)*(c1*exp(x(1)/x(2))+c2*(1-s1));
%xdot(1) = (a1+a2*(x(2)/(b1+x(2)))-(c1*(exp(x(1)/x(2))-exp(1.0))+c2*(x(3))))*x(1)*(1-log(x(1))/a);
xdot(2) = (b2-b3*(exp(x(2)/x(1))-exp(1.0))-(d1+d2*(x(4))))*x(2)*(1-log(x(2))/b);
xdot(1) = (a1+a2*(x(1)/(b1+x(1))))*x(1)*(1-log(x(1))/a)-x(1)*(c1*exp(x(1)/x(2))+c2*(1-x(2)));
%xdot(2) = (b1-b1*0.01*exp(x(2)/x(1)))*x(2)*(1-log(x(2))/b)-x(2)*(d1+d2*(1-x(4)));
Any help would be greatly appreciated!
0 Comments
Answers (1)
Steven Lord
on 22 Nov 2019
As the error message states, your initial condition vector
X0=[C0;S0;s1;s2];
tells ode45 that you're trying to solve a system of four ODEs. However your ODE function
function xdot= badstromarun(~,x,a,a1,a2,b,b1,b2,b3,c1,c2,d1,d2)
xdot = zeros(2,1);
only returns values for two of the four ODEs. This mismatch causes MATLAB to throw the error.
If you have a system of four ODEs (or perhaps two second-order ODEs, in which case your system looks like the van der Pol equation example on this documentation page except with another pair of first-order ODEs constructed from your second second-order ODE) modify badstromarun so it returns a 4-by-1 vector with the values of each of the four ODEs.
If you have a system of two ODEs, change your X0 vector so it only has two elements.
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations 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!