0% found this document useful (0 votes)
25 views85 pages

Lab_Manual_Sem_1-2

The document is a lab manual for the Engineering Mathematics course at BMS College of Engineering, detailing lab procedures, evaluation methods, and topics covered in the first semester. It includes instructions for maintaining lab records, executing programs, and conducting Continuous Internal Evaluations (CIEs). The manual outlines various mathematical concepts and programming tasks using Python, including plotting curves, partial derivatives, and solving differential equations.

Uploaded by

nsvjsv04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views85 pages

Lab_Manual_Sem_1-2

The document is a lab manual for the Engineering Mathematics course at BMS College of Engineering, detailing lab procedures, evaluation methods, and topics covered in the first semester. It includes instructions for maintaining lab records, executing programs, and conducting Continuous Internal Evaluations (CIEs). The manual outlines various mathematical concepts and programming tasks using Python, including plotting curves, partial derivatives, and solving differential equations.

Uploaded by

nsvjsv04
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 85

BMS College of Engineering,

Bangalore-19

Department of Mathematics

LAB MANUAL
First Semester

Engineering Mathematics using


Python

January 19, 2023


General Instructions:
1. Students need to maintain record of every lab and to be submitted to
the concerned faculty for evaluation in the next lab.

2. Students need to go through the lab manual and study the sample
programmes and need to complete the given task in the same lab session
and to show the outputs to the concerned faculty.

3. This course is an integrated course, so that there is no SEM End Exams


for lab. But lab questions will be included in SEE.

4. Any damage / loss of PC components will be viewed seriously.

5. No separate practice labs will be provided.

Method of Evaluation:
1. Lab Record: for submitting a record with complete write up on time
– 5 Marks (for each lab)

2. During Lab Session: For Execution of at least 2 programmes from


exercise problems with proper solutions (for each lab).

3, Lab CIE: Two CIE’s to be conducted each for 10 marks. (First CIE
after 5 labs and second CIE at the end of 10th lab).

4. Eligibility: Minimum 40%(8/20) of marks to be maintained to take


up Theory SEE.

I
II
III
Contents

Contents VI

1 Plotting Cartesian and Polar Curves 1


1.1 Syntax used in this Lab: . . . . . . . . . . . . . . . . . 1
1.1.1 Customizations: . . . . . . . . . . . . . . . . . . 1
1.1.2 Plotting points(Scattered plot): . . . . . . . . . 2
1.1.3 Implicit Function . . . . . . . . . . . . . . . . . 2
1.1.4 Parametric Function: . . . . . . . . . . . . . . . 2
1.2 Sample Programs: . . . . . . . . . . . . . . . . . . . . . 3
1.2.1 Implicit Functions: . . . . . . . . . . . . . . . . 3
1.2.2 Polar Curves: . . . . . . . . . . . . . . . . . . . 5
1.2.3 Parametric Curves: . . . . . . . . . . . . . . . . 6
1.3 Activity-1:Cartesian Curves: . . . . . . . . . . . . . . . 8
1.4 Activity-2:Polar Curves: . . . . . . . . . . . . . . . . . 9
1.5 Activity-3:Parametric Curves: . . . . . . . . . . . . . . 9

2 Angle between polar curves and Radius of curvature 11


2.1 Angle between radius vector and tangent: . . . . . . . . 12
2.1.1 Angle between two polar curves: . . . . . . . . . 12
2.2 Radius of curvature . . . . . . . . . . . . . . . . . . . . 12
2.3 Syntax Used in this Lab: . . . . . . . . . . . . . . . . . 13
2.4 Sample Programs: . . . . . . . . . . . . . . . . . . . . . 14
2.4.1 Angle between Polar Curves: . . . . . . . . . . . 14
2.4.2 Radius of curvature in Cartesian curves: . . . . 15
2.4.3 Radius of curvature in Cartesian curves: . . . . 16
2.4.4 Radius of Curvature of Polar Curves: . . . . . . 17
2.4.5 Radius of Curvature of Parametric Curves: . . . 18
2.5 Activity-1: . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.6 Activity-2: . . . . . . . . . . . . . . . . . . . . . . . . . 19

IV
3 Partial Derivatives and Jacobian 21
3.1 Partial derivatives: . . . . . . . . . . . . . . . . . . . . 21
3.2 Jacobian: . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.3 Syntax Used in Lab: . . . . . . . . . . . . . . . . . . . 22
3.4 Sample Programs: . . . . . . . . . . . . . . . . . . . . . 22
3.4.1 Partial Derivatives: . . . . . . . . . . . . . . . . 22
3.4.2 Jacobian: . . . . . . . . . . . . . . . . . . . . . 24
3.5 Activity-1: . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.6 Activity-2: . . . . . . . . . . . . . . . . . . . . . . . . . 26

4 Extrema of function of two variables: 28


4.1 Syntax: . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.2 Sample Programme: . . . . . . . . . . . . . . . . . . . 29
4.3 Activity: . . . . . . . . . . . . . . . . . . . . . . . . . . 30

5 Solving system of linear equation Ax = b 32


5.1 Syntax for the commands used: . . . . . . . . . . . . . 32
5.2 Solution of system of equations: . . . . . . . . . . . . . 33
5.2.1 System of homogeneous linear equations: . . . . 33
5.3 Sample Programme: . . . . . . . . . . . . . . . . . . . 33
5.4 Non-homogeneous system of Linear Equations: . . . . . 34
5.5 Sample Programme: . . . . . . . . . . . . . . . . . . . 34
5.6 Graphical representation of solution: . . . . . . . . . . 37
5.7 Gauss-Seidel Method: . . . . . . . . . . . . . . . . . . . 38
5.7.1 Sample Programme: . . . . . . . . . . . . . . . 39
5.8 Activity: . . . . . . . . . . . . . . . . . . . . . . . . . . 41

6 Eigenvalues and Eigenvectors 42


6.1 Syntax for the commands used: . . . . . . . . . . . . . 43
6.2 Eigenvalues and Eigenvectors: . . . . . . . . . . . . . . 44
6.2.1 Sample Programme: . . . . . . . . . . . . . . . 44
6.3 Rayleigh power method: . . . . . . . . . . . . . . . . . 45
6.3.1 Sample Programme: . . . . . . . . . . . . . . . 46
6.4 Activity: . . . . . . . . . . . . . . . . . . . . . . . . . . 47

7 Solution of Initial and Boundary value problems: 49


7.1 Syntax for the commands used: . . . . . . . . . . . . . 49
7.2 Sample Programme: . . . . . . . . . . . . . . . . . . . 50
7.3 Activity: . . . . . . . . . . . . . . . . . . . . . . . . . . 53

V
8 Solving Higher order differential equations of Mechan-
ical systems: 55
8.1 Mechanical Systems: . . . . . . . . . . . . . . . . . . . 56
8.2 Sample Program: . . . . . . . . . . . . . . . . . . . . . 57
8.3 Activity-1: . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.4 Activity-2:Mechanical Systems . . . . . . . . . . . . . . 60

9 Deflection of Beams in Civil Engineering : 62


9.1 Deflection of Beams: . . . . . . . . . . . . . . . . . . . 62
9.2 Activity-1: . . . . . . . . . . . . . . . . . . . . . . . . . 65

10 Solving the differential equations of electrical circuits 67


10.1 RLC Series Circuit: . . . . . . . . . . . . . . . . . . . . 68
10.2 Sample Programs: . . . . . . . . . . . . . . . . . . . . . 69
10.3 Activity-1: . . . . . . . . . . . . . . . . . . . . . . . . . 71
10.4 Activity-2: . . . . . . . . . . . . . . . . . . . . . . . . . 71

11 Linear Congruences for Computer Science Cluster 72


11.1 Finding GCD and solving linear Congruence . . . . . . 73
11.1.1 Euclidean algorithm: . . . . . . . . . . . . . . . 73
11.1.2 Sample Programme: . . . . . . . . . . . . . . . 74
11.2 Solving Linear Congruence: . . . . . . . . . . . . . . . 76
11.2.1 Sample Programme: . . . . . . . . . . . . . . . 76
11.3 Activity-1: . . . . . . . . . . . . . . . . . . . . . . . . . 78
11.4 Activity-2: . . . . . . . . . . . . . . . . . . . . . . . . . 78

VI
Introduction to Python:
Please refer to the following ”Link”

Installation of Python:
Please refer to the following ”Link”

Basics of Python:
Please refer to the following ”Link”

Programming Structures in Python:


Please refer to the following ”Link”

VII
LAB: 1

Plotting Cartesian and Polar


Curves

Objectives:
In this lab students will learn

1. to plot the given cartesian equation and identify shape of the curves.

2. to plot polar curves equation and identify shape of the curves.

3. to plot the given implicit functions and identify the curves.

1.1 Syntax used in this Lab:


plot(x, y): plot x and y using default line style and color

1.1.1 Customizations:
ˆ plot(x, y, ’bo’): plot x and y using blue circle markers

ˆ plot(y): plot y using x as index array 0..N-1

ˆ plot(y, ’r+’): ditto, but with red plusses

ˆ plot(x, y, ’go–’, linewidth=2, markersize=12)

ˆ plot(x,y,color=’green’,marker=’o’,linestyle=’dashed’,linewidth=2,
markersize=12)

1
1.1.2 Plotting points(Scattered plot):
scatter(x-axis-data,y-axis-data,s=None,c=None,marker=None,cmap=None,
vmin=None,vmax=None,alpha=None,linewidths=None,edgecolors=None)

1.1.3 Implicit Function


plot implicit(expr,x-var=None,y-var=None,adaptive=True,depth=0,
points=300,line-color=’blue’,show=True,∗∗kwargs)

1.1.4 Parametric Function:


1. Plotting a single parametric curve with a range
plot parametric((expr x, expr y), range)

2. Plotting multiple parametric curves with the same range


plot parametric((expr x, expr y), ..., range)

3. Plotting multiple parametric curves with different ranges


plot parametric((expr x, expr y, range), ...)

2
1.2 Sample Programs:
1.2.1 Implicit Functions:
Example-1: Write a Program to plot the implicit function y 2 (a2 − x2 ) =
(x2 + 2ay − a)2 with a=2

3
Example-2: Write a Program to plot the implicit function
(x2 + y 2 − 2ax)2 = 4a2 (x2 + y 2 ) with a = 0.5.

4
1.2.2 Polar Curves:
Example-3: Write a Program to plot the polar curve four leaved Rose:
r = 2|cos2θ|

5
1.2.3 Parametric Curves:
Example-4: Write a Program to plot the parametric curve(Lissajous
Curves) x = asin(nθ + c); y = bsin(θ)

6
Example-5: Write a Program to plot the parametric curve Cardioid x =
a(t − sin(t)) and y = a(1 − cos(t)) with a = 0.5.

7
1.3 Activity-1:Cartesian Curves:
Exercise: Write the program to Plot the following curves:

1. Catenary :y = acosh(x/a)
x2 y2
2. Hyperbola a2
− b2
=1

3. Lower half of the circle: x2 + 2x = 4 + 4y − y 2

4. Circle x2 + y 2 = a

5. Astroid: x2/3 + y 2/3 = a2/3 , a > 0

6. Strophoid: y 2 (a − x) = x2 (a + x), a > 0

7. Cissiod: y 2 (a − x) = x3 , a > 0

8. Lemniscate: a2 y 2 = x2 (a2 − x2 )

9. Folium of Descartes: x3 + y 3 = 3axy

8
1.4 Activity-2:Polar Curves:
Exercise: Write the program to Plot the following curves:

1. Spiral of Archimedes: r = a + bθ

2. Limacon: r = a + bcosθ

3. Cardioid: r = a + acos(θ)

4. Ellipse: r = √ ab
asin2 (θ)+bcos2 (θ)

5. Circle r = a for a = 1, 2, 3
a2
6. Lituus :r2 = θ

7. Cardioid: r = a − asin(θ)
asin(θ)
8. Cochleoid:r = θ

1.5 Activity-3:Parametric Curves:


Exercise: Write the program to Plot the following curves:

1. Circle: x = acos(θ); y = asin(θ)


3at 3at2
2. Folium of Descartes:x(t) = 1+t3
;y(t) = 1+t3

3. Circle: x = 5cos(θ); y = 5sin(θ)

4. Involute of a Circle:x = a(cost + tsint);y(t) = a(sint − tcost)

5. Cardioid x = a(2cos(t) − cos(2t));y = a(2sin(t) − sin(2t))

6. Nephroid:x(t) = a(3cost − cos(3t));y(t) = a(3sint − sin(3t))


1
7. Tractrix: x = cosht
;y = t − tanht

9
Observations:

10
11
LAB: 2

Angle between polar curves


and Radius of curvature

Objectives:
In this lab students will learn

1. to find the derivative of given function using sympy.

2. to find angle between two polar curves.

3. to find radius of curvature of cartesian and polar curves.

2.1 Angle between radius vector and tangent:


The angle between radius vector and tangent of a polar curve r = f (θ) is
given by tanϕ = r dθ
dr
.

2.1.1 Angle between two polar curves:


If ϕ1 and ϕ2 are angle between radius vector and tangent of two polar curves
then α = |ϕ1 −ϕ2 | is the angle between two curves at the point of intersection.

2.2 Radius of curvature


(1+y12 )3/2
Formula to calculate Radius of curvature in cartesian form is ρ = y2
(r2 +r12 )3/2
Formula to calculate Radius of curvature in polar form is ρ = r2 +2r12 −rr2
3
(x′2 +y ′2 ) 2
The Radius of curvature of Parametric curves is ρ = y ′′ x′ −x′′ y ′
, where x′ =
d2 x dy d2 y
dx
dt
, x′′ = dt2
, y′ = dt
, y ′′ = dt2
.
12
2.3 Syntax Used in this Lab:
ˆ diff(function,variable):-Returns the derivative of function w.r.t the
variable. Here both expression and variable are symbols(it is called
from sympy.

ˆ idiff(Equation,variable 1,variable 2,order):-Return the derivative


of implicit Equation of two variables w.r.t. first variable of given
order.

ˆ subs(): math expression.subs(variable, substitute)-Returns value of


the expression by substituting the variable=substitute.

ˆ Derivative(expression, reference variable):-Returns the deriva-


tive of the expression w.r.t to reference variable. Here both ex-
pression and variables are symbols(it is called from sympy.

ˆ doit(x):-Returns the evaluated object

ˆ simplify(): simplify(expression)-Returns the simplified form of the


expression.

ˆ display(expression):-It is an output statement displays the mathe-


maticalexpression.

13
2.4 Sample Programs:
2.4.1 Angle between Polar Curves:
Example-1:Find the angle between the curves r = a(1 − cost) and
r = b(1 − sint) with a = 3 and b = 4.

14
2.4.2 Radius of curvature in Cartesian curves:
Example-2:(Explicit function)Find the radius of curvature for y =
4sin(x) − sin(2x) at x = π/2.

15
2.4.3 Radius of curvature in Cartesian curves:
Example-3:(Implicit
 3a 3a  function)Find the radius of curvature for x3 + y 3 =
3axy at 2 , 2 .

16
2.4.4 Radius of Curvature of Polar Curves:
Example-4:Find the radius of curvature for r = acos(nt) at t = π/2 and
n = 1.

17
2.4.5 Radius of Curvature of Parametric Curves:
3 3
Example-5:Find the radius of curvature for x = a 2 cos 2 (t) and y =
3 3
a 2 sin 2 (t) at t = π/2 and n = 1.

18
2.5 Activity-1:
1. Find the angle between radius vector and tangent to the following polar
curves and hence find the angle between them:
a) r = aθ and r = aθ ,
b) r = 2sin(θ) and r = 2cos(θ)
c) r = 2(1 + sin(θ)) and r = 2(1 + cos(θ))

2. Find the angle between the following polar curves:


a) r = eaθ and r = e−aθ ,
b) r = 4sin2 (θ) and r = 8sin(θ)
c) r2 = 4sin(2 ∗ θ) and r2 = 4cos(2 ∗ θ)

2.6 Activity-2:
1. Find the radius of curvature of r = 2(1 − cos(t)) at t = π2 .

2. Find the radius of curvature of r = acos(t) at t = π4 .

3. Find the radius of curvature of r = asin(2t) at t = π4 .

4. Find radius of curvature of x = acos3 (t), y = asin3 (t) at t = 0.

5. Find the radius of curvature of x = a(t − sin(t)) andy = a(1 − cos(t))


at t = π.

6. Find the radius of curvature of x(t) = a(3cost − cos(3t));y(t) =


a(3sint − sin(3t))at t = π2 .

7. Find the radius of curvature of x2 + y 2 = 25 at point (3, 4).

8. Find the radius of curvature of y = ccosh xc at the point (0, c).




a(x2 +y 2 )
9. Find the radius of curvature of x2 = y
at the point (−2a, 2a).

10. Find the radius of curvature of y 2 x = 4(2 + x)at ∗ − 2, 1).

19
Observations:

20
LAB: 3

Partial Derivatives and


Jacobian

Objectives:
In this lab will learn

1. to find partial derivatives of multi-variable functions.

2. to find the Jacobian of functions of two and three variables.

3.1 Partial derivatives:


ˆ diff(u,x)= ∂u
∂x

ˆ diff(u,y)= ∂u
∂y

∂2u
ˆ diff(u,x,x)= ∂x2
2
ˆ diff(u,x,y)= ∂x∂y
∂ u

3.2 Jacobian:
Let x = g(u, v) and y = h(u, v) be a transformation of the plane. Then the
∂x ∂x
∂(x,y) ∂u ∂v
Jacobian of this transformation is J = ∂(u,v)
= ∂y ∂y .
∂u ∂v

21
3.3 Syntax Used in Lab:
1. Matrix():
Matrix([[row1],[row2],[row3]....[rown]])
A 3 by 3 matrix can be defined as
Matrix([[a11,a12,a13],[a21,a22,a23],[a31, a32 a33]])

2. Determinant(): or det():
Determinant(M)
M: is input matrix

3.4 Sample Programs:


3.4.1 Partial Derivatives:
Example-1: Find the partial derivatives Ux and Uy and prove that
mixed partial derivatives , Uxy = Uyx for U = ex (xcos(y) − ysin(y)).

22
 
−1 2xy
Example-2: If u = tan x2 −y 2
then prove that uxx + uyy = 0.

23
3.4.2 Jacobian:
xy yz zx
Example-3: If u = z
,v = x
,w = y
then prove that J = 4.

24
Example-4: If X = ρcos(ϕ)sin(θ), Y = ρcos(ϕ)cos(θ), Z = ρsin(ϕ) then
find ∂(X,Y,Z)
∂(ρ,ϕ,θ)
.

3.5 Activity-1:
∂2u ∂2u
1. If u = tan−1 (y/x) verify that ∂y∂x
= ∂x∂y
.
2 2
2. If u = log( xx+y
+y
) then show that xux + yuy = 1.
 
−1 2xy
3. If u = tan x2 −y 2
then show that uxx + uyy = 0.

4. If w = x2 y + y 2 z + z 2 x then show that wx + wy + wz = (x + y + z)2 .


y z
5. If u = z
+ x
show that xux + yuy + zuz = 0.

25
3.6 Activity-2:
1. If x = u − v, y = v − uvw and z = uvw find Jacobian of x, y, z w.r.t
u, v, w.
∂(x,y)
2. If x = rcos(t) and y = rsin(t) then find the ∂(r,t)
.
∂(x,y,z)
3. If x = u + v + w, y = uv + vw + wu and z = uvw find ∂(u,v,w)
.
2yz 3zx 4xy ∂(u,v,w)
4. If u = x
, v= y
and w = z
then find ∂(x,y,z)

y2 y2 ∂(u,v)
5. If u = x + x
and v = x
then find the ∂(x,y)
.

26
Observations:

27
LAB: 4

Extrema of function of two


variables:

Objectives: In this lab students will learn to find the maxima and minima
of function of two variables.

4.1 Syntax:
1. sympy.solve(expression):Returns the solution to a mathematical ex-
pression/polynomial.

2. sympy.evalf():Returns the evaluated mathematical expression.

3. sympy.lambdify(variable, expression, library):Converts a


SymPy expression to an expression that can be numerically evaluated.
lambdify acts like a lambda function, except it, converts the SymPy
names to the names of the given numerical library, usually NumPy or
math.

28
4.2 Sample Programme:
Example-1: Find the maxima and minima of f (x, y) = x3 + 3xy 2 − 15x2 −
15y 2 + 72x.

29
4.3 Activity:
1. Find the maxima and minima of x2 + 2y 2 − 2xy − x − y − 2

2. Find the maxima and minima of x3 + y 3 − 3y − 12x + 20

3. Find the maxima and minima of x2 + y 2 + 6x + 12

4. Find the maxima and minima of x4 + y 4 − y 2 − x2 + 1


a3 a3
5. Find the maxima and minima of xy + x
+ y

6. Find numbers such that sum of three numbers is constant and their
product is maximum.

7. Find the shortest distance from the origin to the surface xyz 2 .

8. Let T = 400xyz 2 is temperature on the surface of sphere x2 +y 2 +z 2 = 4.


Find the point of maximum temperature.

30
Observations:

31
LAB: 5

Solving system of linear


equation Ax = b

Objectives:
In this lab students will learn

1. to test for consistency of the system Ax = b and represent the solution


graphically.

2. to check whether the given system is diagonally dominant or not.

3. to find the solution of the system Ax = b using Gauss-Elimination and


Gauss-Seidel Methods.

5.1 Syntax for the commands used:


ˆ numpy.matrix(data, dtype = None):Returns a matrix from an
array-like object, or from a string of data. A matrix is a specialized
2-D array that retains its 2-D nature through operations.

ˆ numpy.linalg.matrix rank(A):Return rank of the array.

ˆ numpy.shape(A):Returns the shape of an array.

ˆ sympy.Matrix():Creates a matrix.

32
5.2 Solution of system of equations:
5.2.1 System of homogeneous linear equations:
The linear system of equations of the form AX = 0 is called system of
homogeneous linear system of equations. The n-tuple (0, 0, . . . , 0) is a trivial
solution of the system. The homogeneous system of m equations AX = 0 in
n unknowns has a non trivial solution if and only if the rank of the matrix
A is less than n. Further if ρ(A) = r < n, then the system possesses (n − r)
linearly independent solutions.

5.3 Sample Programme:


Example-1:Check whether the following system of homogeneous linear
equations x1 + 2x2 − x3 = 0, 2x1 + x2 + 4x3 = 0 and 3x1 + 3x2 + 4x3 = 0 has
non-trivial solution.

33
5.4 Non-homogeneous system of Linear
Equations:
The linear system of equations of the form AX = B is called system of
non-homogeneous linear equations if not all elements in B are zeros. The
non-homogeneous system of m equations AX = B in n unknowns is

ˆ consistent (has a solution) if and only if, ρ(A) = ρ([A|B])

ˆ has unique solution, ρ(A) = n

ˆ has infinitely many solutions, ρ(A) < n

ˆ system is inconsistent ρ(A) ̸= ρ([A|B]).

5.5 Sample Programme:


Example-2: Examine the consistency of the following system of equations
x1 + 2x2 − x3 = 1, 2x1 + x2 + 4x3 = 2 and 3x1 + 3x2 + 4x3 = 1.

34
Example-2: Examine the consistency of the following system of equations
x1 + 2x2 − x3 = 1, 2x1 + x2 + 4x3 = 2 and 3x1 + 3x2 + 4x3 = 1.

35
36
5.6 Graphical representation of solution:
Example-4: Obtain the solution of 3x + 5y = 1, x + y = 1 graphically.

37
Output:

5.7 Gauss-Seidel Method:


Gauss Seidel method is an iterative method to solve system of linear equa-
tions. PThe method works if the system is diagonally dominant. That is
|aii | ≥ i̸=j |aij | for all i.

38
5.7.1 Sample Programme:
Example-1:Solve the system of equations using Gauss-Seidel method:
10x + y − 2z = 14; 3x + 10y − z = −13; 2x − y + 10z = 17.

39
Example-2: Apply Gauss-Seidel method to solve the system of equations:
20x + y − 2z = 17; 3x + 20y − z = −18; 2x − 3y + 20z = 25.

Example-3: Check whether the given matrix is diagonally dominant or not.


10x + y + 100z = 12; x + 10y + z = 12; x + y + 10z = 12.

40
5.8 Activity:
1. Find the solution of the system of homogeneous equations x+y +z = 0,
2x + y − 3z = 0 and 4x − 2y − z = 0.

2. Find the solution of the system of non-homogeneous equations 25x +


y + z = 27, 2x + 10y − 3z = 9 and 4x − 2y − 12z = −10.

3. Find the solution of the system of non-homogeneous equations x + y +


z = 2, 2x + 2y − 2z = 4 and x − 2y − z = 5.

4. Check whether the following system of equations are consistent


a. x + y + z = 2, 2x + 2y − 2z = 6 and x − 2y − z = 5.
b. 2x + y + z = 4, 4x + 2y − 2z = 8 and 4x + 22y + 2z = 5.

5. Check whether the following system are diagonally dominant or not


a. 25x + y + z = 27, 2x + 10y − 3z = 9 and 4x − 2x − 12z = −10.
b. x + y + z = 7, 2x + y − 3z = 3 and 4x − 2x − z = −1.

6. Solve the following system of equations using Gauss-Seidel Method


a. 4x + y + z = 6, 2x + 5y − 2z = 5 and x − 2x − 7z = −8.
b. 27x + 6y − z = 85, 6x + 15y + 2z = 72 and x + y + 54z = 110

Observations:

41
42
LAB: 6

Eigenvalues and Eigenvectors

Objectives:
In this lab students will learn

1. to find eigen values and corresponding eigen vectors of given matrix.

2. to find dominant eigenvalue and corresponding eigen vector by Rayleigh


power method.

6.1 Syntax for the commands used:


ˆ np.linalg.eig(A):Compute the eigenvalues and right eigenvectors of a
square array
Returns the following:
w(. . . , M) array-The eigenvalues, each repeated according to its mul-
tiplicity. The eigenvalues are not necessarily ordered. The resulting
array will be of complex type, unless the imaginary part is zero in
which case it will be cast to a real type. When a is real the resulting
eigenvalues will be real (0 imaginary part) or occur in conjugate pairs.
v(. . . , M, M) array-The normalized (unit ’length’) eigenvectors, such
that the column v[:, i] is the eigenvector corresponding to the eigen-
value w[i].

ˆ np.linalg.eigvals(A):Computes the eigenvalues of a non-symmetric


array

ˆ np.array(parameter): Creates n-dimensional-array


np.array([[1, 2, 3]]) is a one-dimensional array and
np.array([[1, 2, 3, 6], [3, 4, 5, 8], [2, 5, 6, 1]]) is a multi-dimensional
array.
43
ˆ lambda arguments:expression: Anonymous function or function
without a name. This function can have any number of arguments
but only one expression,which is evaluated and returned. They are
syntactically restricted to a single expression. Example: f = lambda
x : x ∗ ∗2 − 3 ∗ x + 1(Mathematically f (x) = x2 − 3x + 1).

ˆ np.dot(vectora , vectorb ) :Returns the dot product of vectors a and b.

6.2 Eigenvalues and Eigenvectors:


6.2.1 Sample Programme:
Example-1: Writea programme
 to find the eigen values and eigen vectors
5 1 1
of the matrix A =  1 5 1 .
1 1 5

44
6.3 Rayleigh power method:
For a given Matrix A and a given initial eigen vector X0 , the power method
goes as follows:

ˆ Calculate AX0 and take the largest number say λ1

ˆ Write the column vector as AX0 = λ1 X1 . At this stage , λ1 is the


approximate eigen value and X1 will be the corresponding eigen vector.

ˆ Next multiply the Matrix A with X1 and continue the iterations.

ˆ This method is going to give the dominant eigenvalue of the Matrix and
T
it is given by Rayleigh Quotient λmax = xxTAx
x
and x is the corresponding
dominant eigenvector.

45
6.3.1 Sample Programme:
Example-2:Compute
  the numerically largest eigenvalue of P =
25 −2 2
 −2 3 −1  by Rayleigh power method.
2 −1 0

46
6.4 Activity:
1. Find the eigenvalues and eigenvectors
 of the following matrices
  25 1 2
25 1
a. P = b. P =  1 3 0 
1 3
  2 0 −4 
11 1 2 3 1 1
c. P =  0 10 0  d. P =  1 2 1 
0 0 12 1 1 12
2. Find the dominant eigen value of the following matrices using power
method  
25 1 2
a. P =  1 3 0 , Take X0 = (1, 0, 1)T .
 2 0 −4 
6 1 2
b. P = 1 10 −1 , Take X0 = (1, 1, 1)T .

 2 1 −4 
5 1 1
c. P = 1 3 −1 , Take X0 = (1, 0, 0)T .

 2 −1 −4 
4 1 2
d. P = 2 6 −1 , Take X0 = (1, 1, 1)T .

 2 −1 −4 
−2 −2 2
e. P =  1 1 −1 ,Take X0 = (1, 0, −1)T .
 2 −1 −4 
0.5 2 1
f. P =  1 10 −1 ,Take X0 = (−1, 0, 0)T .
 2 −1 4 
5 1 2
g. P =  1 3 −1 ,Take X0 = (1, 0, 1)T .
 2 −1 −4
7 1 1
h. P =  1 7 0 , Take X0 = (−1, −1, 0)T .
2 0 7
3. 
Find the least eigenvalue of the matrix using power method P =
5 1 1
 1 3 −1 . Take X0 = (1, 0, 0)T .
2 −1 −4
47
Observations:

48
LAB: 7

Solution of Initial and


Boundary value problems:

Objectives:
In this lab students will learn

1. to find the solution of first order differential equation subject to given


initial condition.

2. to plot the graph of an analytical solution of the given first order ODE.

7.1 Syntax for the commands used:


1. dsolve(eq, func=None, hint=’default’, simplify=True,
ics=None, xi=None, eta=None, x0=0, n=6, **kwargs):Solves
ordinary differential equation and system of ordinary differential
equations.

3. linspace(start, stop, num=50, endpoint=True, retstep=False,


dtype=None, axix=0): Returns the vector from ”start” and ”stop”
with number of points is equal to ”num”.

49
7.2 Sample Programme:
Example-1: Solve the differential equation y ′ − 2t
1−t2
y = −1 subject to
condition y(1) = 2.

50
4
Example-2: Solve the differential equation y ′ + yt = − yt subject to condition
y(1) = 1.

51
d2 y
Example-3: Solve dt2
− 2 dy
dt
+ y = sin(t) subject to conditions y(0) = 1 and
y ′ (0) = 0..

52
7.3 Activity:
1. Solve ysinxdx − (1 + y 2 + cos2 x)dy = 0.
dy
2. Solve dx = x + y subject to condition y(0) = 2 and plot the graph of
solution.
dy
3. Solve dx = x2 subject to condition y(0) = 5 and plot the graph of
solution.

4. Solve y ′ − y − xex = 0.

5. Solve x2 y ′ = ylog(y) − y ′

Observations:

53
LAB: 8

Solving Higher order


differential equations of
Mechanical systems:

Objectives: In this lab students will learn

1. to solve the differential equation of a mass-spring-dash-pot system .

2. to represent the solution graphically.

54
Solution of second order ordinary differential equation and plotting the so-
lution curve
d2 y dy
A second order differential equation is defined as + P (x) + Q(x)y =
dx2 dx
f (x) where P (x), Q(x) and f (x) are functions of x.When f (x) = 0, the
equation is called homogeneous second order differential equation.

8.1 Mechanical Systems:


The motion of the spring mass system is given by the differential equation
2
m ddt2x + a dx
dt
+ kx = f (t). where, m is the mass of a spring coil,x is the dis-
placement of the mass from its equilibrium position, a is damping constant,
k is spring constant.

1. Free and undamped motion - a = 0, f (t) = 0.


2
Differential Equation : m ddt2x + kx = 0

2. Free and damped motion: f (t) = 0


2
Differential Equation : m ddt2x + a dx
dt
+ kx = 0

3. Forced and damped motion:


2
Differential Equation : m ddt2x + a dx
dt
+ kx = f (t)

55
8.2 Sample Program:
d2 x
Example-1: Solve the mechanical system dt2
+ 64x = 0, x(0) = 41 , x′ (0) = 1.

56
2
Example-2: Solve the mechanical system 9 ddt2x + 2 dx
dt
+ 1.2x = 0, x(0) =

1.5, x (0) = 2.5.

57
d2 x
Example-3: Solve the mechanical system dt2
+ 6 dx
dt
+ 9x = sin(3t), x(0) =
1, x′ (0) = 0.

58
8.3 Activity-1:
1. Solve y ′′ − 5y ′ + 6y = cos(4x)

2. Solve x2 y ′′ − 5xy ′ + 6y = cos(4logx)

3. Solve y ′′ + 2y ′ + 2y = cos(2x), y(0) = 0, y ′ (0) = 0


2
4. 3 ddt2x + 2 dx
dt
− 2x = cos(2x) with x(0) = 0; x′ (0) = 0

8.4 Activity-2:Mechanical Systems


d2 x
1. Solve dt2
+ 64x = 0, x(0) = 14 , x′ (0) = 1
2
2. Solve 9 ddt2x + 2 dx
dt
+ 1.2x = 0, x(0) = 1.5, x′ (0) = 2.5

Observations:

59
LAB: 9

Deflection of Beams in Civil


Engineering :

Objectives: In this lab students will learn

1. to solve the differential equation of a Deflection of beams.

2. to represent the solution graphically.

9.1 Deflection of Beams:

60
61
Example-1: Find the deflection of beam defined by following differen-
4
tial equation ddtQ4 = w subject to boundary conditions Q(0) = 0, Q(2) =
0, Q′ (0) = 0 and Q′ (2) = 0.

62
9.2 Activity-1:
1. Find the displacement in the cantilever beam which is simply supported
one end at x = 0 and and fixed at x = 2.

2. Find the displacement in the beam which is simply supported at x = 0


and x = 3.

3. Find the displacement in the cantilever beam which is fixed at x = 0


and and freely supported x = 4

4. Find the displacement in the beam which is fixed at both ends x = 0


and x = L = 1.

5. Find the displacement in the beam for which bending moment is 0 at


x = 0 and fixed at the other end x = 4.

63
Observations:

64
65
LAB: 10

Solving the differential


equations of electrical circuits

Objectives: In this lab students will learn

1. to solve the differential equations of RC, LR and LRC series circuits.

2. to represent the solution of differential equation in electrical science


graphically.

10.1 RLC Series Circuit:


Let resistance R, Inductance L and capacitance C are connected in series
with an applied emf E(t). Then according to Kirchoff’s law, the sum of the
voltage drops in a closed RLC circuit equals the impressed voltage. Hence
L dI
dt
+ RI + C1 Q = E(t)
This equation contains two unknowns, the current I in the circuit and the
charge Q on the capacitor. However,we know that dQ dt
= I above equation
can be converted into the second order equation in Q, given by
2
L ddtQ2 + R dQ
dt
+ C1 Q = E(t)

1. Free Oscillations: We say that an RLC circuit is in free oscillation if


E(t) = 0 for t > 0, so that above equation becomes
2
L ddtQ2 + R dQ
dt
+ C1 Q = 0

2. Forced Oscillations With Damping: E(t) ̸= 0 and t > 0, we have


2
L ddtQ2 + R dQ
dt
+ C1 Q = E(t)
These equations must be supported with initial conditions:Q(0) =
Q0 , Q′ (0) = I0 .
66
10.2 Sample Programs:
Example-1: Find the current I in the RLC circuit which is defined the
2
differential equation L ddtQ2 + R dQ
dt
+ C1 Q = 0.

67
Example-2: Find the current I in the RLC circuit which is defined the
2
differential equation L ddtQ2 + R dQ
dt
+ C1 Q = E0 cos(ωt).

68
10.3 Activity-1:
ˆ Find the current in the RLC circuit, assuming that E(t) = 0 for t > 0
a) R = 3,L = 0.1,C = 0.01, with conditions zero initial conditions.
b) R = 10,L = 1,C = 0.1, with conditions zero initial conditions.
c) R = 3,L = 0.1,C = 0.01, with conditions zero initial conditions.
d) R = 10,L = 1,C = 0.1, with conditions zero initial conditions.
e) R = 10,L = 1,C = 0.1, with conditions zero initial conditions.

10.4 Activity-2:
ˆ Find the steady state current in the circuit described by the equation:
a) 110I ′′ + 3I ′ + 100I = 10cos10t
b) I ′′ + 3I ′ + 2I = sint
c) 5I ′′ + 10I ′ + 100I = −5cos2t
d) I ′′ + 5I ′ + 5I = et
e) I ′′ + 3I ′ + 10I = 2t

Observations:

69
70
LAB: 11

Linear Congruences for


Computer Science Cluster

11.1 Finding GCD and solving linear Con-


gruence
Objectives: In this lab students will learn

1. to find the gcd of two numbers using Euclid algorithm

2. to express it as linear combination of numbers.

2. to find the solution of the linear congruence.

11.1.1 Euclidean algorithm:


This algorithm is useful to find GCD of two numbers. The algorithm is as
follows:
The two numbers a and b can be assumed positive such that a < b. Let r1 be
the remainder when b is divided by a. Then 0 ≤ r1 < a. That is b = ak1 +r1 .
Now let r2 be the remainder when a is divided by r1 . That is a = r1 k2 + r2 .
Where 0 ≤ r2 < r1 . Continue this process of dividing each divisor by the
next remainder. At some stage we obtain remainder 0. The ”last non-zero
remainder is the GCD” of a and b. This is known as Euclid’s algorithm.

Algorithm analysis:
1. Recursive process - operations are repeated till stopping criterion is
reached.
2. The output of one step is used as the input of the next step.
Relatively Primes: 71
Two numbers a and b are called ”relatively prime” or ”co-prime” if their
GCD (also known as HCF) is equal to 1. For example: 2 and 19 are relatively
prime, because 1 is the largest natural number that divides both 2 and 19.
11.1.2 Sample Programme:
Example-1:Check whether 241 and 512 are relatively prime or not.

72
Example-2: Calculate GCD of (a,b) and express it as linear combination of
a and b. Calculate GCD=d of 21 and 19 , express the GCD as 21x+19y = d.

73
11.2 Solving Linear Congruence:
An equation of the form ax ≡ b(mod m) is called linear congruence relation.
For a given a,b and m, x is called the solution of the congruence. The linear
congruence has a solution if and only if gcd(a, m) divides b.

11.2.1 Sample Programme:


The solution of the congruence ax ≡ 1(mod p) is called multiplicative inverse
of a(modp).
Example-1:Solve the linear congruence 21 ≡ 9mod24.

74
Example-2:Solve the linear congruence 4 ≡ 2mod6.

75
11.3 Activity-1:
1. Find the GCD of 234 and 672 using Euclidean algorithm.

2. What is the largest number that divides both 1024 and 1536?

3. Find the greatest common divisor of 6096 and 5060?

4. Prove that 1235 and 2311 are relatively prime.

5. Are 9797 and 7979 coprime?

6. Write a function in Python to compute the greatest common divisor of


15625 and 69375.

7. Using a Python module, find the GCD of 4096 and 6144.

8. What is the GCD of x4 y + 3xy 2 + 5xy and 2x3 y + 3x2 y 3 + 5x2 y.

11.4 Activity-2:
1. Find the solution of the congruence 12x ≡ 6( mod 23)

2. Find the multiplicative inverse of 3 mod 31

3. Prove that 12x ≡ 7( mod 14) has no solution. Give reason for the
answer.

4. Find the solution of the congruence 5x ≡ 3(mod 13)

5. Check whether 4x ≡ 3(mod 12) has a solution

76
Observations:

77

You might also like