MATLAB: Help! me set the subscript indices properly so the function can perform while loop iterations

subscript indiceswhile loops

Help! me set the subscript indices properly so the function can perform the req'd iterations. MATLAB errors: Subscript indices must either be real positive Error in ==> connection_analysis_1 at 32
j=0; % rotation angle – assumed THETA1(1)=1; % rotation angle – calculated % THETA2(j)=10; r(1)=0;
while (1.00<r(j) r(j)<0.99)
M=1;
T(j)=1/(2*THETA1(j))*(P - ((2*M)/L));
if T(j)>=Tu
DELTA(j)=DELTAu;
else
DELTA(j)=-4E-10*T(j)^4-4E-08*T(j)^3+0.0003*T(j)^2-0.0255*T(j)+0.4375;
end
THETA2(j)=sqrt(2*(T(j)/E*A + DELTA(j)/L) + (T(j)/E*A + DELTA(j)/L)^2);
r(j)=THETA1(j)/THETA2(j);
if j==1
THETA(j+1)=(THETA1(j)+THETA2(j))/2;
else if r(j)>1 && r(j-1)<1 || r(j)<1 && r(j-1)>1
THETA1(j+1)=(THETA2(j-1)+THETA2(j))/2;
else
THETA1(j+1)=(THETA1(j)+THETA2(j2))/2;
end
end
j=j+1;
end

Best Answer

Indices start at 1, so
j=0;
...
while (1.00<r(j) r(j)<0.99)
is referencing a value that does not exist (the 0th value of r). Another problem with this code is that you need to use a logical operator to combine the conditions in the while statement. For example, if you wanted 1.00<r(j) OR r(j)<0.99 then use:
while (1.00<r(j) || r(j)<0.99)