What’s my error ?!
Mostra commenti meno recenti

1 Commento
Adam Danz
il 10 Mar 2020
This is better than the 1-line of code you had previously but an image of code makes it difficult for us to work with since we can't copy-paste it.
Since I already copyied your previous line of code, here's what it should look like when formatted properly.
i=1;
x(i)=5;
error(i)=9999;
while error (i) >=(0.5)
X(i+1)=((x(i)^2-2.5)/(1.8));
error(i+1)=abs((((x(i+1)-x(i))/(x(i+1)))*1000));
i=i+1;
end
To use smart-indentation, highlight all of your code (ctrl+A, in Window, followed by ctrl+i).
Risposte (1)
One reason it's difficult to see the error is because all of your code is in 1 line. There's no advantage to doing this. Disadvantages are
- Really diffcult to read
- Error messages aren't helpful in pointing to the error
- It's realy difficult to see what parts of the code are in loops, etc
Your code contains a variable X (upper case) which should probably be x (lower case).
Also, don't use error as a variable name since error() is a common function.
You should also replace the while-loop with a for-loop if i is an interger starting with 1 that increases incrementally.
2 Commenti
Walter Roberson
il 11 Mar 2020
There are an unknown number of iterations, so you cannot use a for loop.
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!