at the moment I try to understand ode45. So I would like to solve an exercise. The differential equation is: y=y' with y(0)=10. I wrote this code:
tspan = [0 5];
y0 = 10;
[t,y] = ode45(@(t,y) y, tspan, y0);
plot(t,y);
I know that the analytical solution would be the exponential-function. So I inserted it in the plot to verify the solution. (The exp function needs to be shifted by 9 upwards.)
hold on;
fplot(@(x) exp(x)+9,tspan,'r')
But there is a divergence I cannot explain. What I've understand wrong?
The true solution of this diffential equation with this initial condition is :
10*exp(t)for
y'(t) = y(t)the solution is of the form
c.exp(t)with c a constant. Using the initial condition :y0 = 10We have :
c exp(0) = 10therefore
c = 10;Therefore you are not comparing the correct amount,
Use :
fplot(@(x) 10*exp(x),tspan,'r')