MATLAB: Initial conditions on ODE45

numericalnumerical solverode45

Im trying to solve this IVP: e^y +(t*e^y – sin(y))*(dy/dt)=0 with the initial condition y(2)=1.5.
I was just not sure how to do it with the initial condition with Y(2)=1.5, iknow how to do it if it were y(0)=1.5:
f= @(t,y) (exp(y)+(t.*exp(y)-sin(y))); % This is the function.
[t,y]=ode45(f, [0.5,4], 1.5); % trange is from 0.5 to 4
plot(t,y)
can someone please help me out?

Best Answer

This uses the initial value y(0.5)=1.5 ( not y(0)=1.5):
[t, y] = ode45(f, [0.5, 4], 1.5);
So for y(2)=1.5:
[t, y] = ode45(f, [2, 4], 1.5);
Note: The initial value problem starts at the inital point.
[EDITED]: The call to ODE45 is equivalent, if the problem is formulated in backward direction - an "final value problem": tspan is still [ti, tf], but now ti > tf.