I need some help adjusting my system of differential equations code.
Mostrar comentarios más antiguos
I'm having some issues in regards to my code. Currently, this is the code:
l0 = 3; % initial length of plant
w0 = 0; % initial amount of water
n0 = 0; % initial amount of nutrients in dirt
S = 1; % the sun
a = 1;
b = 1;
e = 1; % evaporation
tr = [0 100]; % time from 0 to 10
var0 = [w0, l0, n0, S]; % variables
[tt, xx] = ode45(@(t, x) first_order(x, t, a, b, e), tr, var0); % ode45's set up
w = xx(:,1); % this is w0
n = xx(:,2); % this is n0
L = xx(:,3); % this is l0
S = xx(:,4); % this is S (sun)
if t < 5
Rdash = Val; % step function value (1 in case of unit step function)
else
Rdash = 0;
end
function dLdt = first_order(t, l, a, b, e)
dLdt = zeros(size(l));
C = 1;
R = 1;
dLdt(1) = e+ b.*l(3) + C.*R;
dLdt(2) = a.*l(3);
dLdt(3) = a.*(l(4)+l(1)+l(2))*(2-1/k);
dLdt(4) = dLdt(3);
end
And these are the errors:
>> odecodeforclass
Index exceeds matrix dimensions.
Error in odecodeforclass>first_order (line 20)
dLdt(1) = e+ b.*l(3) + C.*R;
Error in odecodeforclass>@(t,x)first_order(x,t,a,b,e)
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 odecodeforclass (line 10)
[tt, xx] = ode45(@(t, x) first_order(x, t, a, b, e), tr, var0); % ode45's set up
>>
I added some commentary to help. For context, I'm coding this differential system here:
dL/dt = aL(L0 - Lf) where L'=a(S+W+N)(1-1/k)
S = dL where d is constant
W' = E + bL + cR
N' = aL
where E = evaporation, R = rain water, and R'=0 is a step function
[4:29 PM]
S = sun, W = water, N = nutrients
1 comentario
Torsten
el 19 de Mayo de 2021
- function dLdt = first_order(l,t,a,b,e)
- k is undefined in first_order
- Make sure that dLdt is a column vector.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!