Mathematics 6.2 LabManual
Mathematics 6.2 LabManual
LAB MANUAL
MATDSCP6.2:
PRACTICAL’S ON NUMERICAL ANALYSIS
Contents
1 Program to find root of an equation using bisection and Regula-Falsi
methods 1
1.1.2 Program
1
print ( " Iteration : %d ,\ t x = % 0 . 6f \ t f ( x ) = % 0 . 6f " % (i ,x , f ( x ) ) )
if f ( a ) * f ( x ) < 0 :
b=x
else :
a=x
print ( f " The approximate root is { x } " )
1.1.3 Exercise
3. Use the bisection method in four stages to find the real root of the equation
x log10 x − 102 = 0.
2
1.2.2 Exercise
2. Compute the real root of x log10 x − 1.2 = 0 by the method of false position.
3. Use the method of false position to find the fourth root of 32.
4. Find the real root of the equation xex − 3 = 0 by Regula-Falsi method correct to
four decimal places.
def df ( x ) :
return 3 + sin ( x )
3
2.1.2 Exercise
2. Applying Newton-Raphson method to find the real root of the equation x4 −x−10 =
0 which is near to x = 2.
3. Using Newton-Raphson method find a real root of the equation sin x = 1 − x (near
0.5).
4. Using Newton-Raphson method find a real root of the equation x2 + x = cos x (near
0.5).
4
3.2 Exercise
Solve the following system of equations by Gauss elimination method.
1. 5x + 2y + z = 12; x + 4y + 2z = 15; x + 2y + 5z = 0
4.1 Program
Solve by Gauss-Jacobi method 10x + 2y + z = 9; x + 10y − z = −22; −2x + 3y + 10z = 22.
# Solve by Gauss - Jacobi method 10x + 2y + z = 9 ; x + 10y - z = - 22 ; - 2x + 3y + 10z = 22
f1 = lambda x ,y , z : ( 9 - 2 * y - z ) / 10
f2 = lambda x ,y , z : ( - 22 - x + z ) / 10
f3 = lambda x ,y , z : ( 22 + 2 * x - 3 * y ) / 10
# Intitial conditions
x0 , y0 , z0 =0 ,0 , 0
itr = 1
e = float ( input ( " Enter the tolerable error : " ) )
condition = True
print ( " \ n \ itr \ t x \ t y \ t z \ n " )
while condition :
x1 = f1 ( x0 , y0 , z0 )
y1 = f2 ( x0 , y0 , z0 )
z1 = f3 ( x0 , y0 , z0 )
print ( " % d \ t % 0 . 4f \ t % 0 . 4f \ t % 0 . 4f \ n " % ( itr , x1 , y1 , z1 ) )
e1 = abs ( x0 - x1 ) ; e2 = abs ( y0 - y1 ) ; e3 = abs ( z0 - z1 )
itr + = 1
x0 = x1 ; y0 = y1 ; z0 = z1
condition = e1 > e and e2 > e and e3 > e
print ( " \ n Solution : x = % 0 . 4f , y = % 0 . 4f , z = % 0 . 4f \ n " % ( x1 , y1 , z1 ) )
4.2 Exercise
Solve the following system of equations by Gauss-Jacobi method.
1. 5x + 2y + z = 12; x + 4y + 2z = 15; x + 2y + 5z = 0
5
2. 10x − 2y + z = 12; x + 9y − z = 10; 2x − y + 11z = 20
5.1 Program
5.2 Exercise
Solve the following system of equations by Gauss-Seidel method.
1. 5x − 2y + z = −4; x + 6y − 2z = −1; 3x + y + 5z = 13
6
6 Program to solve the system of algebraic equations
using SOR method
6.1 Program
6.2 Program
7
7 Program to evaluate integral using Trapezoidal rule
7.1 Program
R6 1
Evaluate dx taking n = 6 using trapezoidal rule.
0 1 + x2
# Evaluate int_0 ^ 6 ( 1 /( 1 + x ^ 2 ) ) dx taking n = 6 using trapezoidal rule
x0 = int ( input ( " Lower limit of the interval : " ) )
xn = int ( input ( " Upper limit of the interval : " ) )
n = int ( input ( " Number of sub intervals : " ) )
def f ( x ) :
return ( 1 / ( 1 + x ** 2 ) )
h = ( xn - x0 ) / n
sum1 = f ( x0 ) + f ( xn )
for i in range (1 , n ) :
sum1 = sum1 + 2 * f ( x0 + i * h )
print ( " Estimated value of given integration : " ,h / 2 * sum1 )
7.2 Exercise
R5
1. Evaluate log10 xdx taking n = 6.
1
R3 1
2. Evaluate dx taking n = 6.
1 1+x
R6 1
3. Evaluate dx taking n = 6.
0 1 + x2
8
8 Program to evaluate integral using Weddle’s rule
8.1 Program
R6 1
Evaluate dx taking n = 6 using Weddle’s rule.
0 1 + x2
# Evaluate int_0 ^ 6 ( 1 /( 1 + x ^ 2 ) ) dx taking n = 6 using Weddle 's rule
x0 = int ( input ( " Lower limit of the interval : " ) )
xn = int ( input ( " Upper limit of the interval : " ) )
n = int ( input ( " Number of sub intervals : " ) )
def f ( x ) :
return ( 1 / ( 1 + x ** 2 ) )
h = ( xn - x0 ) / n
sum1 = f ( x0 ) + f ( xn )
for i in range (1 ,n , 6 ) :
sum1 = sum1 + ( 5 * f ( x0 + i * h ) + f ( x0 + ( i + 1 ) * h ) + 6 * f ( x0 + ( i + 2 ) * h ) + f ( x0 + ( i + 3 ) * h ) +
5 * f ( x0 + ( i + 4 ) * h ) )
print ( " Estimated value of given integration : " ,3 * h / 10 * sum1 )
8.2 Exercise
R5
1. Evaluate log10 xdx taking n = 6.
1
R3 1
2. Evaluate dx taking n = 6.
1 1+x
R6 1
3. Evaluate dx taking n = 6.
0 1 + x2
9
9 Program to evaluate integral using Simpson’s one-
third rule and Simpson’s three-eighth rule
9.1.1 Program
9.1.2 Exercise
R5
1. Evaluate log10 xdx taking n = 6.
1
R3 1
2. Evaluate dx taking n = 6.
1 1+x
R6 1
3. Evaluate dx taking n = 6.
0 1 + x2
9.2.1 Program
10
# Evaluate int_0 ^ 6 ( 1 /( 1 + x ^ 2 ) ) dx taking n = 6 using Simpson 's three - eighth
rule
x0 = int ( input ( " Lower limit of the interval : " ) )
xn = int ( input ( " Upper limit of the interval : " ) )
n = int ( input ( " Number of sub intervals : " ) )
def f ( x ) :
return ( 1 / ( 1 + x ** 2 ) )
h = ( xn - x0 ) / n
sum1 = f ( x0 ) + f ( xn )
for i in range (1 , n ) :
if i % 3 = = 0 :
sum1 = sum1 + 2 * f ( x0 + i * h )
else :
sum1 = sum1 + 3 * f ( x0 + i * h )
print ( " Estimated value of given integration : " ,3 * h / 8 * sum1 )
9.2.2 Exercise
R5
1. Evaluate log10 xdx taking n = 6.
1
R3 1
2. Evaluate dx taking n = 6.
1 1+x
R6 1
3. Evaluate dx taking n = 6.
0 1 + x2
11
10 Program to find differentiation at specified point
using Newton-Gregory interpolation method
10.1 Program:
10.2 Program:
10.3 Program:
12