Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Index exceeds the number of array elements (1)

1 vue (au cours des 30 derniers jours)
Ben Nolan
Ben Nolan le 24 Mar 2020
Clôturé : MATLAB Answer Bot le 20 Août 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 commentaires
Ameer Hamza
Ameer Hamza le 25 Mar 2020
How are you calling this function. Which line is giving this error?
Ben Nolan
Ben Nolan le 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)

Réponses (1)

the cyclist
the cyclist le 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