Can someone please help me out with this MATLAB code. It is giving error "INDEX EXCEEDS THE NUMBER OF ARRAYS_ INDEX MUST NOT EXCEED 1" ON LINE 69

1 view (last 30 days)
clear ALL
m11 = int8 ( zeros (100) )
% T1t(i) = int8 ( Zeros (100))
% T2t(i) = int8( Zeros (100))
m1 = 1 ;
m2 = 2;
l1 = 1;
l2 = 1.2;
I1 = 0.12;
I2 = 0.25 ;
me = 2 ;
Ic1 = 0.25 ;
Ic2 = 0.6 ;
v1 = 5.5 ;
v2 = 2.7 ;
k1 = 2 ;
k2 = 1 ;
g = 9.8 ;
dt= 0.01
% t = 0 ;
Points = 30000
Data = zeros(Points,4);
D = [ 100 ; 50];
F = [ 30 ; 30 ]
theta1t(1) = 1 ;
theta2t(1) = 0.01 ;
thetav1t(1) = 0;
thetav2t(1) = 0 ;
thetaa1t((1)) = 0 ;
thetaa2t((1)) = 0 ;
for i = 1 : 1000
t(i) = i
t(i+1) = (i+1)* dt
qd1 = pi/6*(1-cos(2*pi*t(i))+1.5*sin(.5*pi*t(i)))
qd2 = pi/4*(1-cos(2*pi*t(i))+2.5*sin(.75*pi*t(i)))
qdv1 = (pi^2)/3*sin(2*pi*t(i))+(pi/6)*(1.5*0.5*pi)*cos(.5*pi*t(i))
qdv2 = (pi^2)/2*sin(2*pi*t(i))+(pi/4)*(2.5*0.75*pi)*cos(.75*pi*t(i))
qda1 = 2*(pi^3)/3*cos(2*pi*t(i))-(pi/6)*(1.5*0.5*pi)*(0.5*pi)*sin(.5*pi*t(i))
qda2 = (pi^3)*cos(2*pi*t(i))-(pi/4)*(2.5*0.75*pi)*(0.75*pi)*sin(.75*pi*t(i))
m11 = ((l2*l2*m2)/(2*l1*l2*m2*cos(theta2t(i))))+( l1*l1*(m1-m2))
m12 = ( l2*l2*m2) + ( l1*l2*m2*cos(theta2t(i)))
m21 = (( l2*l2*m2 )/(l1*l2*m2*cos(theta2t(i))))
m22 = ( l2*l2*m2 )
m = [ m11 , m12 ; m21 ,m22]
v11 = (-m2*l1*l2*sin(theta2t(i))*(thetav2t(i))*(thetav2t(i))) -( 2*m2*l1*l2*sin(theta2t(i))*(thetav1t(i))*(thetav2t(i)))
v21 = m2*l1*l2*sin(theta2t(i))*(thetav1t(i))*(thetav1t(i))
V = [v11;v21 ]
G11= (m2*l2*g*cos(theta1t(i)+theta2t(i))) + (( m1+m2)*l1*cos(theta1t(i)))
G21 = m2*l2*g*cos(theta1t(i) + theta2t(i))
G = [G11; G21]
T1(i) = m2*l2*l2*(thetaa1t(i)+thetaa2t(i)) + (m2*l1*l2*cos(theta2t(i))*(2*thetaa1t(i)) + thetaa2t(i)) + ((m1+m2)*l1*l1*thetaa1t(i)) - (m2*l1*l2*(sin(theta2t(i)))*thetav2t(i)*thetav2t(i)) - ( 2*m2*l1*l2*(sin(theta2t(i)))*thetav1t(i)*thetav2t(i))+(m2*l2*g*sin(theta1t(i)+theta2t(i))) + ((m1+m2)*l1*g*sin(theta1t(i)))+(v1*thetav1t(i))+(k1*sin(thetav1t(i)))
T2(i) = (m2*l1*l2*cos(theta2t(i))*thetaa1t(i)) +(m2*l1*l2*sin(theta2t(i))*thetav1t(i)*thetav1t(i)) + (m2*l2*g*sin(theta1t(i)+theta2t(i)))+(m2*l2*l2*(thetaa1t(i)+thetaa2t(i)))+(v2*thetav2t(i))+(k2*sin(thetav2t(i)))
T = [ T1(i) ;T2(i)]
n = inv(m)
thetaa = n*[T -V - G -F -D]
thetaa1t(i) = thetaa(1,1)
thetaa2t(i) = thetaa(2,1)
thetav1t(i+1) = thetav1t(i) +thetaa1t(i)*dt
thetav2t(i+1) = thetav2t(i)+ thetaa2t(i)*dt
theta1t(i+1) = theta1t(i) + thetav1t(i)*dt +( 1/2)*thetaa1t(i)*dt*dt
theta2t(i+1) = theta2t(i) + thetav2t(i)*dt + (1/2)*thetaa2t(i)*dt*dt
% Errors
e1t(i) = abs(theta1t(i)-qd1)
e2t(i) = abs(theta2t(i) - qd2)
ed1t(i) = abs(thetav1t(i)- qdv1)
ed2t(i) = abs(thetav2t(i)-qdv2)
end
ax = gca ;
ax.XAxislocation = "origin";
ax.YAxislocation ="origin";
xlabel ( 'time');
ylabel ('Torque1') ;
Legend ('T1','T2')
Plot ( t , T1,'r')
hold on
Plot (t,T2 ,'b')
hold off

Answers (1)

DGM
DGM on 25 Apr 2022
Edited: DGM on 25 Apr 2022
thetaa1t and thetaa2t are initialized as scalars
thetaa1t((1)) = 0 ;
thetaa2t((1)) = 0 ;
I imagine you're trying to grow them, but when you make the assignments here, you're only assigning to the current index instead of i+1, so they never grow.
thetaa1t(i) = thetaa(1,1)
thetaa2t(i) = thetaa(2,1)
... that's probably why.

Categories

Find more on Solar Power in Help Center and File Exchange

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!