Index out of bounds?

I was given a project to work on with a crank with link R, and a slider with link L. I am supposed to run the algorithm to calculate from 1 to 100 each being a different point to calculate the angle between the links R and L, position of the slider, angular velocity between R and L, velocity of the slider, and then angular acceleration between R and L, and acceleration of the slider.
Part of the code which I have written is as follows:
R = 0.5; % m length of the lower arm of the slider
L = 1.25; % m length of the upper arm of the slider
thetadot = 2*pi; % radians/second angular velocity of the slider
theta = linspace(0,4*pi,100); % all angles of the lower slider arm
for i = 1:100
f1 = @(phi) (R*sin(theta(i))) + (L*sin(phi)) - H;
df1 = @(phi) (L*(cos(phi)));
phi0 = (pi/4);
phi(i) = newtraph(f1,df1,phi0,0.0001,50);
% invoke newtraph to find roots for phi
f2 = @(s) (R*cos(theta(i))) + (L*cos(phi(i))) - s;
df2 = @(s) -1;
s0 = sqrt((H.^2) + ((R + L)^2));
s(i) = newtraph(f2,df2,s0,0.0001,50);
% invoke newtraph to find roots for s
A1 = [-L*sin(phi(i)), -1; L*cos(phi(i)), 0];
* b1 = [(R*sin(theta(i))*thetadot(i)); (-R*cos(theta(i))*thetadot(i))];
x1 = A1\b1; % x1 = angualar and linear velocity
phidot = x1(1); sdot = x1(2);
This is only part of the code, however, even with just this piece of the code I am getting an error that states:
Attempted to access thetadot(2); index out of bounds because numel(thetadot)=1.
  • the line with the * is the line where the error appears. I do not understand what this error means or how to fix it, any help is greatly appreciated.
Thank you!
Lia

 Accepted Answer

Matt J
Matt J on 10 Mar 2013
Edited: Matt J on 10 Mar 2013

0 votes

Since thetadot=2*pi is just a scalar, you cannot run a loop over thetadot(i) for i=1...100 as if thetadot were a length 100 vector. Perhaps you meant to have theta(i) there instead of thetadot(i).

More Answers (0)

Categories

Asked:

Lia
on 10 Mar 2013

Community Treasure Hunt

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

Start Hunting!