Negative initial value problem. Index must be a positive integer or logical.

3 views (last 30 days)
When I tried to run this code :
yprime= @(t,y) (.01)*(6*(t^5)-10*(t^4)-104*(t^3)+84*(t^2)+290*t-26)
y(-4)= 0.4
t_range = [-4,5]
I get this error message: "Attempted to access y(-4); index must be a positive integer or logical."
Any ideas for how to fix this. I am just learning MatLab and I don't think we are expected to do anything too advanced.

Accepted Answer

Star Strider
Star Strider on 3 Feb 2016
Initial conditions have to start at t=0, understood by definition. You would have to define it a ‘y0 = 0.4’.
This works:
yprime= @(t,y) (.01)*(6*(t^5)-10*(t^4)-104*(t^3)+84*(t^2)+290*t-26);
y0= 0.4;
t_range = [-4,5];
[t,y] = ode45(yprime, t_range, y0);

More Answers (0)

Community Treasure Hunt

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

Start Hunting!