Solving Differential Equations in Matlab (numerically)

PHOTO EMBED

Sat Mar 20 2021 07:33:24 GMT+0000 (UTC)

Saved by @FlorianC #matlab

# where derivFunction is a fHandle representing the derivative of the dependent variable wrt. the independent variable
# [tSol, ySol] = ode45(derivFunction,interval,initialValue)

# Example:
r = 1;
K = 1000;
# the variables must be passed as independent variable first followed by the dependent variable
odefun = @(t,P) r*P*(1-P/K);
# solution interval values for t
tSpan = [0,10];
P0 = 20;
[tSol, PSol] = oder45(odefun,tSpan,P0)

# plot results
plot(tSol, PSol);
content_copyCOPY