Info

This question is closed. Reopen it to edit or answer.

Index exceeds the number of array elements (1)

1 view (last 30 days)
Ben Nolan
Ben Nolan on 24 Mar 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
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
Ameer Hamza
Ameer Hamza on 25 Mar 2020
How are you calling this function. Which line is giving this error?
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)

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!