Professional Documents
Culture Documents
The Problem
(x2 + 1.0) 1.0 in two ways
Problem 2 : Evaluate the expression y = (a.)y < (x2 + 1.0) 1.0 2 (b.)y < 2 x
(x +1.0)+1.0
for small values of x, x=0.1, 0.01 and 0.001, Determine the fractional error in both the methods of performing the subtraction. Which method is superior, and why?
2
2.1
Method
The program
#include<stdio.h> #include<math.h> main() { double y1,y2; float x; printf("\n\n \t\tEnter the value of X :: "); scanf("%f",&x); //The first expression y1=sqrt(x*x+1.0)-1.0; //The second expression
2.2
Y1 :: Y2 ::
4.999875e-05 4.999875e-05
Y1 :: Y2 ::
5.000000e-09 5.000000e-09
Results
Here we see the lower the value of X ,the greater is the fractional error.We get fractional error greater than Computer Epsilon from values of X <0.01
For calculating fractional error,we have to know the actual value of the expression.In this case even if we expand the 2nd expression in series,we have to terminate that to a nite extent and that makes it dicult to evaluate the actual value.I have taken one of the values(Y2) to be actual and calculated the fractional error. OS: Fedora 16 Text Editor : vi,gedit Prepared using : TEX