MATLAB Answers

Index exceeds the number of array elements (1)

1 view (last 30 days)
Ben Nolan
Ben Nolan on 24 Mar 2020
Answered: the cyclist on 25 Mar 2020
function [] = diggerangle(L_12, L_23, L_13, x)
iteration_limit = 20;
tolerance = 10^-7;
x = [x(1)*(pi/180);x(2)*(pi/180)];
for count = 1:iteration_limit + 1
if count == iteration_limit + 1
error('Iteration limit reached. Iteration did not converge.')
end
f = [L_12*cos(x(1))-(L_13)-L_23*cos(x(2));...
L_12*sin(x(1))-L_23*sin(x(2))];
if abs(f)<tolerance
break
end
df = [-L_12*sin(x(1))+L_23*sin(x(2));...
L_12*cos(x(1))-L_23*cos(x(2))];
x = x - inv(df)*f;
end
x(1);
x(2);
x(1)*(180/pi)
x(2)*(180/pi)
end
  2 Comments
Ben Nolan
Ben Nolan on 25 Mar 2020
line 6: x = [x(1)*(pi/180);x(2)*(pi/180)];
this is the problem it is giving me the error: Index exceeds the number of array elements (1)

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 25 Mar 2020
You didn't answer Ameer's first question, but it seems clear that when you call the function
diggerangle(L_12, L_23, L_13, x) % what are the inputs here?
that the value of x is simply a scalar, and not a vector. Therefore,
x(2)
is going to give an error, because x only has one element.

Community Treasure Hunt

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

Start Hunting!

Translated by