ODE45 ERROR en el @odefun

6 views (last 30 days)
Mauro Gonzalez
Mauro Gonzalez on 16 Mar 2023
Answered: Torsten on 16 Mar 2023
Hola!
Estoy utilizando el comando ODE45 para resolver una ecuación diferencial pero me da erro en la función que utilizo para el ODE45,
Me aparecen los siguientes errores, ¿a que se refiere con ''Index exceeds matrix dimensions''?.
clear all
clc
tspan=[0:0.1:10]
tspan = 1×101
0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 2.8000 2.9000
CI=[0 0]
CI = 1×2
0 0
[t Y]= ode45(@resode,tspan,CI)
Ix = 3.7835e+03
Mfip = 3.4812e+03
Mfipp = 1196
Mdel = 1.3342e+03
fi1 = 0
fi2 = 0
dfi1 = 0
dfi2 = 0
Index exceeds the number of array elements. Index must not exceed 1.

Error in solution>resode (line 36)
dfidt=[dfi1(1);dfi2(2)]

Error in odearguments (line 92)
f0 = ode(t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
plot(tspan,Y(:,1),'-','b')
hold on
grid on
plot (tspan,Y(:,2),'.','g')
La función es:
function dfidt=resode(t,fi)
delta1 = pi/12*sin(pi*t/3);
delta2 = 0 ;
delta3 = -pi/12* sin((t-4)*0.5*pi);
delta4 = 0 ;
Delta=((t>0)&(t<=3)).*delta1 + ((t>3)&(t<=4)).*delta2 + ((t>4)&(t<=6)).*delta3 + (t>6).*delta4;
Ix=3783.5
Mfip=3481.2
Mfipp=1196
Mdel=1334.2
fi1=fi(1)
fi2=fi(2)
dfi1=fi(2)
dfi2=-Mfip*fi2/(Ix-Mfipp)+Mdel*Delta/(Ix-Mfipp)
dfidt=[dfi1(1);dfi2(2)]
end

Accepted Answer

Torsten
Torsten on 16 Mar 2023
Use
dfidt=[dfi1;dfi2];
instead of
dfidt=[dfi1(1);dfi2(2)]

More Answers (0)

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!