- for loop ends when error<tol
- while loop continues when error<tol
This question is closed. Reopen it to edit or answer.
need help for transfer Whlile loop from For loop
1 view (last 30 days)
Show older comments
pepper on 1 Oct 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
two newton method written with for and while loop.
the result is quite different
where should i fix it?
big thx from bottom of my heart.
switching between text and code blocks helps readability
issues in both
- regardless of what value is passed to the function, you set a=5
- error is an important built-in function, use a different variable name
- you have more p variables than necessary (you only need two)
differences between codes:
- tol is not the same
- "while" error is defined incorrectly
- "while" returns a variable that is never defined (p1)
My comment on consistency referred to the fact that your original "while" screenshot wasn't doing anything in particular each loop.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!