You are on page 1of 3

Computational Physics Lab Test 2011

Sayan Chatterjee 11PH40043 January 25, 2012

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

y2=pow(x,2)/(sqrt(x*x+1.0)+1.0); //Fractional Error

printf("\n\n\tY1 ::\t %e \n\n\t Y2 ::\t %e \n\n\t Fractional Error :: %e \n",y1,y2 }

2.2

Inputs and Outputs from Linux Terminal

[sayan@Sayan C_Programs]$ ./prob2

Enter the value of X :: 0.01

Y1 :: Y2 ::

4.999875e-05 4.999875e-05

Fractional Error :: 8.131720e-16

***************************************** [sayan@Sayan C_Programs]$ ./prob2

Enter the value of X :: 0.0001

Y1 :: Y2 ::

5.000000e-09 5.000000e-09

Fractional Error :: -8.237065e-13

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

Discussions and Conclusions

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

You might also like