Error: Subscript indices must either be real positive integers or logicals

Hi,
I get the error message "Subscript indices must either be real positive integers or logicals." in the following line of code.
Error in doubleODE (line 14)
dYdt(2) = l1*(m1 + m2)*Y(4) - l2*m2*Y(3)*cos(Y(1) - Y(2))/...
I am struggling to work out what is wrong. Any advice?
Thanks Daniel
Edit: Below is the function
function dYdt = doubleODE(t,Y,flag,g,l1,l2,m1,m2)
C1 = Y(3)*Y(4)*sin(Y(1) - Y(2))/l1*l2*(m1 + m2*(sin(Y(1) - Y(2)))^2);
C2 = l2^2*m2*(Y(3))^2 + l1^2*(m1 + m2)*(Y(4))^2 - l1*l2*m2*Y(3)*Y(4)*cos(Y(1) - Y(2))/...
2*l1^2*l2^2*(m1 + m2*(sin(Y(1) - Y(2)))^2)^2;
dYdt = zeros(4,1); %'4' means there are 4 1st order ODEs
dYdt(1) = (l2*Y(3) - l1*Y(4)*cos(Y(1) - Y(2)))/...
(l1^2*l2*(m1 + m2*(sin(Y(1) - Y(2)))^2));
dYdt(2) = (l1*(m1 + m2) - l2*m2*Y(3)*cos(Y(1) - Y(2)))/...
(l1*l2^2*m2(m1 + m2*(sin(Y(1) - Y(2)))^2));
dYdt(3) = -(m1 + m2)*g*l1*sin(Y(1)) - C1 + C2;
dYdt(4) = -m2*g*l2*sin(Y(2)) + C1 - C2;

Answers (1)

The error is in this line
dYdt(2) = (l1*(m1 + m2) - l2*m2*Y(3)*cos(Y(1) - Y(2)))/...
(l1*l2^2* m2(m1 + m2*(sin(Y(1) - Y(2)))^2));
it should be
dYdt(2) = (l1*(m1 + m2) - l2*m2*Y(3)*cos(Y(1) - Y(2)))/...
(l1*l2^2*m2*(m1 + m2*(sin(Y(1) - Y(2)))^2));
It's m2*(m1+m2 istead of m2(m1+m2

This question is closed.

Tags

Asked:

on 16 Mar 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!