Negative initial value problem. Index must be a positive integer or logical.
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
peas
le 3 Fév 2016
Réponse apportée : Star Strider
le 3 Fév 2016
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.
0 commentaires
Réponse acceptée
Star Strider
le 3 Fév 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);
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!