error: Attempted to access y(2); index out of bounds because numel(y)=1 in system of ode
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
tasos statiou
am 15 Nov. 2017
Kommentiert: tasos statiou
am 15 Nov. 2017
Hello.i have a problem writing a code for solving a system of ode
function dydt = myode(t,y,ft,f1,f2)
dydt = zeros(2,1);
f1 = interp1(ft,f1,t); % Interpolate the data set (ft,f) at time t
f2 = interp1(ft,f2,t); % Interpolate the data set (ft,f) at time t
dydt(1) = f1*(y(1).^3*((1/(y(2).^2)+1/(y(1).^2)-1)).^3/2)
dydt(2) = f2*(y(2).^3*((1/(y(1).^2)+1/(y(2).^2)-1)).^3/2)
and
ft = linspace(0,120,25);
tspan = [1 120];
y0 = [1 1];
ic=1;
opts = odeset('RelTol',1e-2,'AbsTol',1e-4);
[t,y] = ode45(@(t,y) myode(t,y,ft,f1,f2), tspan,ic, opts);
when i try to call my function it says
Attempted to access y(2); index out of bounds because numel(y)=1.
Error in myode (line 6)
dydt(1) = f1*(y(1).^3*((1/(y(2).^2)+1/(y(1).^2)-1)).^3/2)
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 15 Nov. 2017
The message is correct. You passed the scalar ic for the initial conditions, which is a little surprising as you have a y0 of the proper length defined by never used.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!