Mathematics 510
Winter 2005
Problem Set 1 Solutions
Problems
1.
(a) Write and execute a program to determine your computer’s machine epsilon and display
the result. Check this with the builtin routine if one exists with your software (eps in
Matlab).
Here is a program to do both
and realmin in one go.
#include<math.h>
#include<iostream.h>
int main()
{
double temp = 1.5, factor = 0.5;
int N = 0;
while( temp > 1 ) //Find Machine Epsilon
{
factor *= 0.5;
temp = 1+factor;
N++;
}
cout << N << endl; // Then eps
= 2

N
.
while(factor > 0) //Find smallest floating point number
{
factor *= 0.5;
N++;
}
cout << N << endl; // Then min
= 2

N
.
return 0;
}
On my machine, eps= 2

52
and min = 2

1074
. If you used Maple to do this, you may
have gotten completely differnt results. This is due to the symbolic nature of Maple.
(b) Graph the two functions
f
1
(
x
) = (1 +
x
)

1 and
f
2
(
x
) =
x
vs.
x
on the same plot for x
ranging from 0 to about 10 times the machine epsilon. If the two plots are not the same
explain the difference.
If you did this in Matlab you should have gotten two different pictures. The graph of
x
vs.
x
is simply a diagonal line. For
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Winter '05
 Kolasa
 matlab, Numerical Analysis, #include, Det, point number, machine epsilon

Click to edit the document details