Info

This question is closed. Reopen it to edit or answer.

need help writing a loop m file

1 view (last 30 days)
Mark
Mark on 18 Oct 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
What I'm trying to do is this problem: http://puu.sh/chhdo.png
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

Answers (1)

Guillaume
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
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!