determining machine epsilon through steps

5 vues (au cours des 30 derniers jours)
Chulwoong
Chulwoong le 17 Sep 2014
Commenté : Chulwoong le 17 Sep 2014
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.

Réponse acceptée

Guillaume
Guillaume le 17 Sep 2014
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 commentaire
Chulwoong
Chulwoong le 17 Sep 2014
got it right, much appreciated!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by