Error "??? Attempted to access p(15); index must be a positive integer or logical."
古いコメントを表示
I am getting error . Please help me its urgent "Warning: FOR loop index is too large. Truncating to 2147483647. > In NR at 7 ??? Attempted to access p(15); index must be a positive integer or logical.
Error in ==> NR at 11 p(q+1)=yi(k+1);"
When i debug this program
%Newton Rapson Method Iteration
clc
s=0:1:100;
yi=1:0.1:300;
for xi=0:0.01:5
for k=1:1:inf
yi(k+1)=yi(k)-(fvalue(xi,yi(k))/dvalue(xi,yi(k)));
e=((yi(k+1)-yi(k))/yi(k+1))*100;
q=xi*100;
p(q+1)=yi(k+1);
if (e<5)&(e>-5)
p
break
end
end
end
回答 (2 件)
Matt Fig
2011 年 3 月 28 日
In general, q will not be an integer. See the many discussions on floating point arithmetic here and on CSSM.
Also, perhaps a WHILE loop would be better? This will rid you of that warning message.
k = 1;
while 1
% Your code here, no FOR loop needed. Use loop counter k.
k = k + 1;
end
Walter Roberson
2011 年 3 月 28 日
k = 0;
while true
k = k + 1;
....
end
"for" loops should not be used for infinite loops.
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!