Lab_Manual_Sem_1-2
Lab_Manual_Sem_1-2
Bangalore-19
Department of Mathematics
LAB MANUAL
First Semester
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.
Method of Evaluation:
1. Lab Record: for submitting a record with complete write up on time
– 5 Marks (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).
I
II
III
Contents
Contents VI
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
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
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”
VII
LAB: 1
Objectives:
In this lab students will learn
1. to plot the given cartesian equation and identify shape of the curves.
1.1.1 Customizations:
plot(x, y, ’bo’): plot x and y using blue circle markers
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)
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
4. Circle x2 + y 2 = a
7. Cissiod: y 2 (a − x) = x3 , a > 0
8. Lemniscate: a2 y 2 = x2 (a2 − x2 )
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 = θ
9
Observations:
10
11
LAB: 2
Objectives:
In this lab students will learn
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.6 Activity-2:
1. Find the radius of curvature of r = 2(1 − cos(t)) at t = π2 .
a(x2 +y 2 )
9. Find the radius of curvature of x2 = y
at the point (−2a, 2a).
19
Observations:
20
LAB: 3
Objectives:
In this lab will learn
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
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.
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
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.
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
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 .
30
Observations:
31
LAB: 5
Objectives:
In this lab students will learn
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.
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
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:
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.
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.
Observations:
41
42
LAB: 6
Objectives:
In this lab students will learn
44
6.3 Rayleigh power method:
For a given Matrix A and a given initial eigen vector X0 , the power method
goes as follows:
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
Objectives:
In this lab students will learn
2. to plot the graph of an analytical solution of the given first order ODE.
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
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.
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)
Observations:
59
LAB: 9
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.
63
Observations:
64
65
LAB: 10
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
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.
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?
11.4 Activity-2:
1. Find the solution of the congruence 12x ≡ 6( mod 23)
3. Prove that 12x ≡ 7( mod 14) has no solution. Give reason for the
answer.
76
Observations:
77