MATLAB Answers

Error in ode45; Graphing ODE

1 view (last 30 days)
Isaiah Duhme
Isaiah Duhme on 20 Nov 2020
Answered: Star Strider on 20 Nov 2020
I'm trying to graph two ODE, but I keep getting an error.
function dcdt = CODE(t,p)
v1 = 330;
v2 = 170;
cbar = 10;
k = 5.5;
cdcdt = [ p(1).*((p(2)*k+k)/v1);
p(2).* ((k*p(1)-k)-cbar/v2)];
t0 = 0;
tfinal = 180;
p0 = [1; 1];
[t,p] = ode45(@CODE, [t0 tfinal],p0);
title('Concentrations over time')
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in concen (line 6)
[t,p] = ode45(@CODE, [t0 tfinal],p0);


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 20 Nov 2020
Note that ‘cdcdt’ is not the same as ‘dcdt’.
Change this to:
dcdt = [ p(1).*((p(2)*k+k)/v1);
and it works, although it has a singularity at t=5.726570e+00, and stops with an appropriate warning.
We all encounter our own typographical errors, so no worries!


Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by