I have a higher order system of ode's that I am trying to solve using ode45. I am receiving an error:
Subscript indices must either be real positive integers or logicals.
My two files are below, followed by a complete list of errors.
function xdot = fdynamics(t,y)
F = 0;
T = 0;
m1 = 2;
m2 = 3;
g = 9.81;
l1 = 1;
l2 = 1;
xdot(1) = y(2);
xdot(2) = (F-m2*g*sin(y(3)))/m2 + (l1+y(1))*y(4)^2;
xdot(3) = y(4);
xdot(4) = (T-(2*m2*(l1+y(1)))*y(4)*y(2) - g*cos(y(3))*(m1*(l1/2)+m2*(l1+y(1))) /((1/3)*m1*(l1)^2 + (1/12)*m2*l2^2 + m2(l1+y(1))^2));
xdot = xdot';
end
//AND//
clc
clear
options = odeset('Refine',1','MaxStep',1/60);
[t,y]=ode45(@fdynamics,[0 5],[0; 0; 0; 0],options);
plot(t,y(:,1),'-x')
title('D vs t');
xlabel('Time t');
ylabel('D');
legend('D')
figure
plot(t,y(:,2),'-x')
title('D-Dot vs t');
xlabel('Time t');
ylabel('D-Dot');
legend('D-Dot')
figure
plot(t,y(:,3),'-x')
title('Theta vs t');
xlabel('Time t');
ylabel('Theta');
legend('Theta')
figure
plot(t,y(:,4),'-o')
title('Theta-Dot vs t');
xlabel('Time t');
ylabel('Theta-Dot');
legend('Theta-Dot')
//ERRORS//
Subscript indices must either be real positive integers or
logicals.
Error in fdynamics (line 16)
xdot(4) = (T-(2*m2*(l1+y(1)))*y(4)*y(2) -
g*cos(y(3))*(m1*(l1/2)+m2*(l1+y(1))) /((1/3)*m1*(l1)^2 +
(1/12)*m2*l2^2 + m2(l1+y(1))^2));
Error in ode45 (line 262)
f(:,3) = feval(odeFcn,t+hA(2),y+f*hB(:,2),odeArgs{:});
Error in attempt2 (line 9)
[t,y]=ode45(@fdynamics,[0 5],[0; 0; 0; 0],options);

 Respuesta aceptada

Star Strider
Star Strider el 15 de Sept. de 2016

1 voto

You’re missing a multiplication operator:
xdot(4) = (T-(2*m2*(l1+y(1)))*y(4)*y(2) - g*cos(y(3))*(m1*(l1/2)+m2*(l1+y(1))) /((1/3)*m1*(l1)^2 + (1/12)*m2*l2^2 + m2*(l1+y(1))^2));
↑ — INSERT MULTIPLICATION OPERATOR HERE
Without the operator (I assume you intend multiplication), MATLAB assumes ‘m2’ is an array, and throws that error.

2 comentarios

Christopher Secrest
Christopher Secrest el 15 de Sept. de 2016
Thank you, I've been stuck on this system for weeks.
Star Strider
Star Strider el 15 de Sept. de 2016
My pleasure.
You have my sympathies. If it makes you feel any better, I’ve had the same sort of problem, and I’m confident many if not most here have.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de Sept. de 2016

Comentada:

el 15 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by