Lab Manual Engineering Maths 2 VTU
Lab Manual Engineering Maths 2 VTU
of
Second Semester Engineering Mathematics
Instructions and method of evaluation
1. In each Lab student have to show the record of previous Lab.
2. Each Lab will be evaluated for 15 marks and finally average will be taken for 15
marks.
3. Viva questions shall be asked in labs and attendance also can be considered for
everyday Lab evaluation.
4. Tests shall be considered for 5 marks and final Lab assessment is for 20 marks.
2
Contents: Electrical & Electronics Engineering Stream
Lab 1. Finding gradient, divergent, curl and their geometrical interpretation and Verification of
Green’s theorem
Lab 2. Solution of algebraic and transcendental equation by Regula-Falsi and Newton- Raphson
method
Lab 3. Interpolation /Extrapolation using Newton’s forward and backward difference formula
Lab 4. Solution of ODE of first order and first degree by Taylor’s series and Modified Euler’s
method
Lab 5. Solution of ODE of first order and first degree by Runge-Kutta 4th order method and
Milne’s predictor and corrector method
3
LAB 1: Finding gradient, divergent, curl and their
geometrical interpretation and Verification of Green’s
theorem
Objectives:
Use python
1.1 Method I:
1. To find gradient of ϕ = x2y + 2xz − 4.
# To find gradient of scalar point function.
from sympy. vector import *
from sympy import symbols
N= Coord Sys3 D ('N') # Setting the coordinate system
x,y, z= sy mbols( ' x y z')
A=N. x ** 2 * N. y+ 2 * N. x* N. z- 4 # Variables x,y, z to be used with coordinate
system N
delop =Del() # Del operator
display ( delop ( A)) # Del operator applied to A
grad A = gra dient( A) # Gradient function is used
print( f"\ n Gradient of { A} is \ n")
display ( grad A )
4
# To find curl of a vector point function
from sympy. vector import *
from sympy import symbols
N= CoordSys3D(' N')
x,y, z= symbols( 'x y z')
A=N. x ** 2 * N. y* N. z* N. i+N. y ** 2 * N. z* N. x* N. j+N. z ** 2 * N. x* N. y* N. k
delop =Del()
curlA = delop . cross( A)
display ( curlA )
5
1.2 Green’s theorem
Statement of Green’s theorem in the plane: If P(x, y) and Q(x, y) be two con- tinuous
functions having continuous partial derivatives in a region R of the xy-plane, bounded by
a simple closed curve C, then
𝝏𝑸 𝝏𝑷
∮(𝑷 𝒅𝒙 + 𝑸 𝒅𝒚) =∬𝑹 ( 𝝏𝒙 − 𝝏𝒚 ) 𝒅𝒙 𝒅𝒚.
I= -1
1. Using Green’s theorem, evaluate ∮𝑐 [(xy + y2)dx + x2dy], where c is the closed
curve bounded by y = x and y = x2.
from sympy import *
var('x, y')
p=x* y+y ** 2
q=x ** 2
f=diff (q, x)-diff (p, y)
soln = integrate (f,[y, x ** 2 , x],[x,0 , 1 ])
print(" I=", soln )
I= -1/20
6
LAB 2: Solution of algebraic and transcendental equa-
tion by Regula-Falsi and Newton-Raphson method
2.1 Objectives:
Use python
% % %
7
# % x^3 - 2 *x- 5 ; function
#% 1
8
# n= 5 ;
9
LAB 3: Interpolation /Extrapolation using Newton’s
forward and backward difference formula
3.1 Objectives:
Use python
1. to interpolate using Newton’s Forward interpolation method.
10
2.
Use Newtons backward interpolation to obtain the interpolating polynomial and
x: 1 3 5 7 9
hence calculate y(8) for the following data:
y: 6 10 62 210 502
n number
11
12
13
LAB 4: Solution of ODE of first order and first degree
by Taylor’s series and Modified Euler’s method
4.1 Objectives:
Use python
D =
H =
H
h
# Append
14
The required values are :at x= 0.00, y=0.00000, x=0.10, y=0.34850,
x = 0.20, y=0.81079,x = 0.30, y=1.41590
15
h = 25
n = 4
16
LAB 5: Solution of ODE of first order and first de-
gree by Runge-Kutta 4th order method and Milne’s
predictor and corrector method
5.1 Objectives:
1. To write a python program to solve first order differential equation using 4th order
Runge Kutta method.
2. To write a python program to solve first order differential equation using Milne’s
predictor and corrector method.
y0 = 2
17
x1 =x0 +h
x2 =x1 +h
x3 =x2 +h
x4 =x3 +h
18
LAB 6: Solution of second order ordinary differential
equation with initial/boundary conditions and plotting the
solution curve
6.1 Objectives:
Use python
Example 1:
19
Example 2:
Plot the solution curves of y′′ + 2y′ + 2y = cos(2x), y(0) = 0, y′(0) = 0
We can turn this into two first-order equations by defining a new depedent variable.
For example,
z = y′ ⇒ z′ + 2z + 2y = cos(2x), z(0) = y(0) = 0.
y′ = z; y(0) = 0
z′ = cos(2x) − 2z − 2y; z(0) = 0.
import numpy as np
from scipy. integrate import odeint
import matplotlib . pyplot as plt
U0 = [0 , 0 ]
xs = np. linspace (0 , 10 , 200 )
Us = odeint( dU_dx , U0 , xs)
20
LAB 7: Solution of differential equation of oscillations
of a spring with various load
7.1 Objectives:
Use python
Example 1:
2
Solve d x + 64x = 0, x(0)=1/4, x′(0) = 1 and plot the solution curve.
dt2
import numpy as np
from scipy. integrate import odeint
import matplotlib . pyplot as plt
y0 =[ 1 /4 , 1 ]
xs=np. linspace (0 ,5 , 50 )
21
Example 2:
2
Solve 9 d x + 2 dx + 1.2x = 0, x(0) = 1.5, x′(0) = 2.5 and plot the solution curve.
dt2 dt
import numpy as np
from scipy. integrate import odeint
import matplotlib . pyplot as plt
y0 =[ 2 .5 , 1 . 5 ]
xs=np. linspace (0 , 20 * np. pi , 2000 )
22
LAB 8: Visualization in time and frequency domain of
standard functions
8.1 Objectives:
Use python
1. to use the standard in-built function of Laplace transform.
Represent the Laplace transform of f(t) = e2t, both in time and frequency domains
23
24
LAB 9: Computing Laplace transform and inverse
Laplace transform of standard functions
9.1 Objectives:
Use python
n ocon d s= Tru e ))
n ocon d s= Tru e ))
25
9.3 Inverse Laplace Transform
26
27
LAB 10: Laplace transform of convolution of two
functions
10.1 Objectives:
Use python
1. to calculate Laplace Transform for convolution of two functions.
2. to verify Convolution Theorem for two given functions.
28
2. Verify the Convolution Theorem for Laplace transform of the functions f(t) = t and
g(t) = et.
F
=
29
Contents: Computer Science and Engineering Stream
Lab 1. Finding gradient, divergent, curl and their geometrical interpretation
Lab 2. Solution of algebraic and transcendental equation by Regula-Falsi and Newton- Raphson
method
Lab 3. Interpolation /Extrapolation using Newton’s forward and backward difference formula
Lab 4. Solution of ODE of first order and first degree by Taylor’s series and Modified Euler’s
method
Lab 5. Solution of ODE of first order and first degree by Runge-Kutta 4th order method
Lab 6. Solution of ODE of first order and first degree by Milne’s predictor-corrector method
30
LAB 1: Finding gradient, divergent, curl and their
geometrical interpretation
1.1 Objectives:
Use python
1.2 Method I:
2. To find gradient of ϕ = x2y + 2xz − 4.
# To find gradient of scalar point function.
from sympy. vector import *
from sympy import symbols
N= Coord Sys3 D ('N') # Setting the coordinate system
x,y, z= sy mbols( ' x y z')
A=N. x ** 2 * N. y+ 2 * N. x* N. z- 4 # Variables x,y, z to be used with coordinate
system N
delop =Del() # Del operator
display ( delop ( A)) # Del operator applied to A
grad A = gra dient( A) # Gradient function is used
print( f"\ n Gradient of { A} is \ n")
display ( grad A )
31
# To find curl of a vector point function
from sympy. vector import *
from sympy import symbols
N= CoordSys3D(' N')
x,y, z= symbols( 'x y z')
A=N. x ** 2 * N. y* N. z* N. i+N. y ** 2 * N. z* N. x* N. j+N. z ** 2 * N. x* N. y* N. k
delop =Del()
curlA = delop . cross( A)
display ( curlA )
32
LAB 2: Solution of algebraic and transcendental equa-
tion by Regula-Falsi and Newton-Raphson method
2.1 Objectives:
Use python
% % %
33
# % x^3 - 2 *x- 5 ; function
#% 1
34
# n= 5 ;
35
LAB 3: Interpolation /Extrapolation using Newton’s
forward and backward difference formula
3.1 Objectives:
Use python
1. to interpolate using Newton’s Forward interpolation method.
36
3.
Use Newtons backward interpolation to obtain the interpolating polynomial and
x: 1 3 5 7 9
hence calculate y(8) for the following data:
y: 6 10 62 210 502
n number
37
38
39
LAB 4: Solution of ODE of first order and first degree
by Taylor’s series and Modified Euler’s method
4.1 Objectives:
Use python
D =
H =
H
h
# Append
40
The required values are :at x= 0.00, y=0.00000, x=0.10, y=0.34850,
x = 0.20, y=0.81079,x = 0.30, y=1.41590
41
h = 25
n = 4
42
LAB 5: Solution of ODE of first order and first de-
gree by Runge-Kutta 4th order method
5.1 Objectives:
1. To write a python program to solve first order differential equation using 4th order
Runge Kutta method.
2. To write a python program to solve first order differential equation using Milne’s
predictor and corrector method.
43
2. Find y(0.1) by Runge Kutta method when y′ = x − y2, y(0) = 1.
y(0.1) = 0.91379
44
LAB 6: Solution of ODE of first order and first de-
gree by Milne’s predictor and corrector method
y14 =f( x4 , y4 );
45
2. Solve by Milnes method: y′ = x – y^2, y(0)=0, y(0.2)=0.02, y(0.4)=0.0795,
y(0.6)=0.1762.Compute y at x=0.8 Use corrector formula thrice.
y14 =f( x4 , y4 );
46
LAB 7: Solution of second order ordinary differential
equation with initial/boundary conditions and plotting the
solution curve
7.1 Objectives:
Use python
Example 1:
47
Example 2:
Plot the solution curves of y′′ + 2y′ + 2y = cos(2x), y(0) = 0, y′(0) = 0
We can turn this into two first-order equations by defining a new depedent variable.
For example,
z = y′ ⇒ z′ + 2z + 2y = cos(2x), z(0) = y(0) = 0.
y′ = z; y(0) = 0
z′ = cos(2x) − 2z − 2y; z(0) = 0.
import numpy as np
from scipy. integrate import odeint
import matplotlib . pyplot as plt
U0 = [0 , 0 ]
xs = np. linspace (0 , 10 , 200 )
Us = odeint( dU_dx , U0 , xs)
48
LAB 8: Solution of differential equation of oscillations
of a spring with various load
8.1 Objectives:
Use python
Example 1:
2
Solve d x + 64x = 0, x(0)=1/4, x′(0) = 1 and plot the solution curve.
dt2
import numpy as np
from scipy. integrate import odeint
import matplotlib . pyplot as plt
y0 =[ 1 /4 , 1 ]
xs=np. linspace (0 ,5 , 50 )
49
Example 2:
2
Solve 9 d x + 2 dx + 1.2x = 0, x(0) = 1.5, x′(0) = 2.5 and plot the solution curve.
dt2 dt
import numpy as np
from scipy. integrate import odeint
import matplotlib . pyplot as plt
y0 =[ 2 .5 , 1 . 5 ]
xs=np. linspace (0 , 20 * np. pi , 2000 )
50
LAB 9: Programme to compute area, volume and cen-
ter of gravity
9.1 Objectives:
Use python
2. integrate:
integrate ( function ,( variable , min_limit , max_limit))
1/3
Example 2:
81/80
51
Example 3:
Example 4:
2 2
dydx
b= 6
24.0*pi
∫∫
9.4 Area of the region R in the polar form is rdrdθ
R
Example 5:
Find the area of the cardioid r = a(1 + cosθ) by double integration
from sympy import *
r= Symbol( 'r')
t= Symbol('t')
a= Symbol('a')
# a= 4
52
∫∫ ∫
9.5 Volume of a solid is given by dxdydz
V
Example 6:
Find the volume of the tetrahedron bounded by the planes x=0,y=0 and z=0, x + y + z = 1
a b c
from sympy import *
x= Symbol( 'x')
y= Symbol('y')
z= Symbol('z')
a= Symbol('a')
b= Symbol('b')
c= Symbol('c')
w2 = integrate (1 ,( z,0 , c*( 1 - x/ a- y/ b)) ,(y,0 , b*( 1 - x/ a)) ,(x,0 , a))
print( w2 )
a*b*c/6
5*a/6
53
54
LAB 10 : Evaluation of improper integrals, Beta and
Gamma functions
10.1 Objectives:
Use python
1. to evaluate improper integrals using Beta function.
2. to evaluate improper integrals using Gamma function.
Parameters :
x : The number whose gamma value needs to be computed.
2. beta
math . beta (x, y)
Parameters :
x ,y: The numbers whose beta value needs to be computed.
3. Note: We can evaluate improper integral involving infinity by using inf.
Example 1:
1
∫∞
Gamma function is x(n) = e−xxn−1dx
0
Example 2:
Evaluate Γ(5) by using definition
from sympy import *
x= s y mbols ( ' x')
w1 = integrate ( exp (- x)* x ** 4 ,( x,0 , float (' inf')))
print( simplify ( w1 ))
24
55
Example 4:
Find Beta(3,5), Gamma(5)
# beta and gamma functions
from sympy import beta , gamma
m= input('m :');
n= i nput(' n :');
m= float( m);
n= float( n);
s= beta(m, n);
t= gamma ( n)
print(' gamma (',n, ') is % 3 . 3f'% t)
print(' Beta (',m,n, ') is % 3 . 3f'% s)
m :3
n :5
gamma ( 5.0 ) is 24.000
Beta ( 3.0 5.0 ) is 0.010
Example 6:
Verify that Beta(m, n) = Gamma(m)Gamma(n)/Gamma(m + n) for m=5 and n=7
from sympy import beta , gamma
m= 5 ;
n= 7 ;
m= float( m);
n= float( n);
s= beta(m, n);
t=( gamma ( m)* gamma ( n))/ gamma ( m+n);
print(s, t)
if ( abs( s- t) <= 0 . 00001 ):
print(' beta and gamma are related ')
else :
pri nt(' given values are wrong ')
0.000432900432900433 0.000432900432900433
beta and gamma are related
56
Contents: Mechanical & Civil Engineering Stream
Lab 6. Solution of ODE of first order and first degree by Runge-Kutta 4th order method
and Milne’s predictor and corrector method
57
LAB 1: Finding gradient, divergent, curl and their
geometrical interpretation
1.1 Objectives:
Use python
1.2 Method I:
2. To find gradient of ϕ = x2y + 2xz − 4.
# To find gradient of scalar point function.
from sympy. vector import *
from sympy import symbols
N= Coord Sys3 D ('N') # Setting the coordinate system
x,y, z= sy mbols( ' x y z')
A=N. x ** 2 * N. y+ 2 * N. x* N. z- 4 # Variables x,y, z to be used with coordinate
system N
delop =Del() # Del operator
display ( delop ( A)) # Del operator applied to A
grad A = gra dient( A) # Gradient function is used
print( f"\ n Gradient of { A} is \ n")
display ( grad A )
58
# To find curl of a vector point function
from sympy. vector import *
from sympy import symbols
N= CoordSys3D(' N')
x,y, z= symbols( 'x y z')
A=N. x ** 2 * N. y* N. z* N. i+N. y ** 2 * N. z* N. x* N. j+N. z ** 2 * N. x* N. y* N. k
delop =Del()
curlA = delop . cross( A)
display ( curlA )
59
Lab 2: Verification of Green’s theorem
2.1 Objectives:
1. To evaluate integrals using Green’s theorem.
I= -1
3 Using Green’s theorem, evaluate ∮𝑐 [(xy + y2)dx + x2dy], where c is the closed
curve bounded by y = x and y = x2.
from sympy import *
var('x, y')
p=x* y+y ** 2
q=x ** 2
f=diff (q, x)-diff (p, y)
soln = integrate (f,[y, x ** 2 , x],[x,0 , 1 ])
print(" I=", soln )
I= -1/20
60
LAB 3: Solution of algebraic and transcendental equa-
tion by Regula-Falsi and Newton-Raphson method
3.1 Objectives:
Use python
% % %
61
# % x^3 - 2 *x- 5 ; function
#% 1
62
# n= 5 ;
63
LAB 4: Interpolation /Extrapolation using Newton’s
forward and backward difference formula
4.1 Objectives:
Use python
1. to interpolate using Newton’s Forward interpolation method.
64
2.
Use Newtons backward interpolation to obtain the interpolating polynomial and hence
x: 1 3 5 7 9
calculate y(8) for the following data:
y: 6 10 62 210 502
n number
65
66
67
LAB 5: Solution of ODE of first order and first degree
by Taylor’s series and Modified Euler’s method
5.1 Objectives:
Use python
D =
H =
H
h
# Append
68
The required values are :at x= 0.00, y=0.00000, x=0.10, y=0.34850,
x = 0.20, y=0.81079,x = 0.30, y=1.41590
69
h = 25
n = 4
70
LAB 6: Solution of ODE of first order and first de-
gree by Runge-Kutta 4th order method and Milne’s
predictor and corrector method
6.1 Objectives:
1. To write a python program to solve first order differential equation using 4th order
Runge Kutta method.
2. To write a python program to solve first order differential equation using Milne’s
predictor and corrector method.
y0 = 2
71
x1 =x0 +h
x2 =x1 +h
x3 =x2 +h
x4 =x3 +h
72
LAB 7: Solution of Lagrange’s linear partial differen-
tial equations
7.1 Objectives:
Use python
73
74
LAB 8: Visualization in time and frequency domain of
standard functions
8.2 Objectives:
Use python
1. to use the standard in-built function of Laplace transform.
Represent the Laplace transform of f(t) = e2t, both in time and frequency domains
75
76
LAB 9: Computing Laplace transform and inverse
Laplace transform of standard functions
9.4 Objectives:
Use python
n ocon d s= Tru e ))
n ocon d s= Tru e ))
77
9.6 Inverse Laplace Transform
78
79
LAB 10: Laplace transform of convolution of two
functions
10.1 Objectives:
Use python
1. to calculate Laplace Transform for convolution of two functions.
2. to verify Convolution Theorem for two given functions.
80
2. Verify the Convolution Theorem for Laplace transform of the functions f(t) = t and
g(t) = et.
F
=
81
82