The following algorithm (attributed to Clever Moler) estimates machine precision
ID: 3748134 • Letter: T
Question
The following algorithm (attributed to Clever Moler) estimates machine precision (eps): a = 4.0/3.0; b = a 1.0; c = b + b + b; eps = abs(c 1.0). Implement the program in C++, Java, or Python twice with single and double precision variable types and report the value of eps for both single and double precision.
2. (10 points) The following algorithm (attributed to Clever Moler) estimates machine precision (eps): a 4.0/3.0; ba-1.0 epsabs(c-1.0). Implement the program twice with single and double precision variable types and report the value of eps for both single and double precisionExplanation / Answer
Here is the required code for this problem in Java. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks
// EPS.java
public class EPS {
public static void main(String[] args) {
// finding eps using single precision (float) variables
float a = (float) (4.0 / 3.0);
float b = (float) (a - 1.0);
float c = b + b + b;
float result = (float) (c - 1.0);
float eps1 = Math.abs(result);
System.out.println("eps for single precision variables: " + eps1);
// finding eps using double precision (float) variables
double x = 4.0 / 3.0;
double y = x - 1.0;
double z = y + y + y;
double eps2 = Math.abs(z - 1.0);
System.out.println("eps for double precision variables: " + eps2);
}
}
/*OUTPUT*/
eps for single precision variables: 1.1920929E-7
eps for double precision variables: 2.220446049250313E-16
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.