Index exceeds the number of array elements (1) error

1 view (last 30 days)
Greetings,
I'm trying to make a position analysis of a mechanism via Newton-Raphson algorithm and when I constructed my model matrixes, I have this error "Index exceeds the number of array elements (1)" and I couldn't decide how to reduce my index. Could that error occurs because of that I'm missing something while giving the parameters? Whole model is given below:
clc, clear all;
%initiating physical parameters
a2=29;a3=15;a4=16;a5=27;a6=25;th4=332*pi/180;thd=240*pi/180;
%initiating max iteration
Nmax=100;
%initiating guess values for th3, th5, th6, to
x=[14*pi/180,59*pi/180,323*pi/180,32];
%initiate error tolerance
xe=0.001*abs(x);
%initiating system inputs
dth=5*pi/180;
th2=-30*pi/180:dth:30*pi/180;
w2=35*ones(1,length(th2));
al2=0*ones(1,length(th2));
%-------------------------
xe=transpose(abs(xe));
kerr=1;
for k=1:1:length(th2);
for n=1:Nmax
%-------------------
%assign initial gues to unknowns
th3(k)=x(1);th5=x(2);
th6=x(3);to=x(4);
%jacobian matrix
J=zeros(4,4)
J(1,1)=-a3*sin(th3(k));J(2,1)=a3*cos(th3(k));
J(3,2)=-a5*sin(th5(k));
J(3,3)=-a6*sin(th6(k));
J(3,4)=-1;
J(4,2)=a5*cos(th5(k));J(4,3)=a6*cos(th6(k));
%INPUT: FUNCTIONS
f=zeros(4,1);
f(1,1)=(a2*cos(th2(k))+a3*cos(th3(k))+a4*cos(th4)+a5*cos(thd)-43);
f(2,1)=(a2*sin(th2(k))+a3*sin(th3(k))+a4*sin(th4)+a5*sin(thd)+31);
f(3,1)=(a5*cos(th5(k))+a6*cos(th6(k))-to(k));
f(4,1)=(a5*sin(th5(k))+a6*sin(th6(k))-12);
%----------------
eps=inv(J)*f;x=x+transpose(eps);
if abs(eps)<xe
kerr=0;break
end
end
if kerr==1
'Error nr'
end
th3(k)=x(1);th5(k)=x(2);
th6(k)=x(3);to(k)=x(4)
end
thank you for answers.

Accepted Answer

Bruno Luong
Bruno Luong on 10 Nov 2018
%assign initial gues to unknowns
th3(k)=x(1);th5=x(2);
th6=x(3);to=x(4);
I think it should be
th3(k)=x(1);
th5(k)=x(2);
th6(k)=x(3);
to(k)=x(4);

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!