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

7 ビュー (過去 30 日間)
peas
peas 2016 年 2 月 3 日
回答済み: Star Strider 2016 年 2 月 3 日
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.

採用された回答

Star Strider
Star Strider 2016 年 2 月 3 日
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);

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by