break loop when answer is same as last answer
조회 수: 1(최근 30일)
Im trying to break this loop when x(i)==x(i-1), but i get...
Attempted to access x(0); index must be a positive integer or logical.
Error in test (line 13)
Here is the code...
func= input('Please enter f(x) = ');
Xest= input('Pleae enter an initial guess = ');
for i = 0:15
x = x-((fs)./(ds));
Andrew Reibold 2014년 12월 2일
The reason it is failing - Matlab does NOT accept ZERO indices. The very first value of x is x(1), not x(0). Your script calls for x(0)!
Why does i go from 0 to 15 instead of 1 to 15? And even then, you will have x(i-1) which is still 0! You will have to rethink through how you do this to avoid x(0)