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);

 채택된 답변

Star Strider
Star Strider 2016년 9월 15일

1 개 추천

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

Christopher Secrest
Christopher Secrest 2016년 9월 15일
Thank you, I've been stuck on this system for weeks.
Star Strider
Star Strider 2016년 9월 15일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2016년 9월 14일

댓글:

2016년 9월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by