Help! me set the subscript indices properly so the function can perform while loop iterations
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
Brian B
el 1 de Abr. de 2013
Editada: Brian B
el 1 de Abr. de 2013
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)
5 comentarios
Brian B
el 1 de Abr. de 2013
Are you sure it runs once? With the AND condition in the while statement, it should not run at all given the initial value of r (r(1)==0.1). Do you want to run the loop UNTIL (0.99<r(k) && r(k)<=1.00)? If so, use
while ~(0.99<r(k) && r(k)<=1.00)
Brian B
el 1 de Abr. de 2013
My suggestion would be to set a breakpoint and step through the program to see where it begins doing things you didn't expect. Try writing down the same steps it should follow on a piece of paper and compare the values at each step. If breakpoints are new, you might find this helpful: http://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html#brqxeeu-184.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!