Info
This question is closed. Reopen it to edit or answer.
need help writing a loop m file
1 view (last 30 days)
Show older comments
This is what I have, but it's not working too well:
clear all
x_old = 20;
x_new = 0;
i = 0;
while x_new >= 2.1
x_new = (2*x_old)^.5
i = i-1
x_old = x_new;
end
0 Comments
Answers (1)
Guillaume
on 18 Oct 2014
Your only problem is that you start with
x_new = 0
So your
while x_new >= 2.1
is false and you never enter the loop.
Start with
x_new = 20;
and it'll all work.
1 Comment
Image Analyst
on 18 Oct 2014
Since i is decremented after the x_new value is obtained, you might need to increment it once you've exited the loop to restore the i to what it should be.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!