필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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

채택된 답변

Brian B
Brian B 2013년 4월 1일
편집: Brian B 2013년 4월 1일
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
Brian B
Brian B 2013년 4월 1일
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
Brian B 2013년 4월 1일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by