determining machine epsilon through steps

I was doing my homework, and it asks me to write a code to determine epsilon. The question was to write code based on these steps
Step 1: Set ε = 1.
Step 2: If 1 + ε is less than or equal to 1, then go to Step 5. Otherwise go to Step 3.
Step 3: ε = ε/2
Step 4: Return to Step 2
Step 5: ε = 2 × ε
So I wrote,
e=1
while e+1>=1
e=e/2;
end
e=2*e;
however, not only looks like MATLAB doesn't want to process this, but also stopped working. I still can type codes but none of them actually getting registered. I just started to learn MATLAB, so I know almost nothing about it. Anyone can help me?
I'm using MATLAB through Citrix, by the way.

 採用された回答

Guillaume
Guillaume 2014 年 9 月 17 日

2 投票

You made a mistake with step 2, the condition to stop is: 1+e <= 1, thus the condition to continue is 1+e > 1. As it is your loop continues forever as when e equal epsilon, e+1 == 1

1 件のコメント

Chulwoong
Chulwoong 2014 年 9 月 17 日
got it right, much appreciated!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2014 年 9 月 17 日

コメント済み:

2014 年 9 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by