Lab Manual BMATS101
Lab Manual BMATS101
COMPLIED BY
DR. D. UMADEVI, PROF. SNEHA
Department of Engineering Mathematics,
HKBK College of Engineering, Bengaluru.
Department of Engineering Mathematics, HKBKCE
1
Department of Engineering Mathematics, HKBKCE
2
Department of Engineering Mathematics, HKBKCE
1. Write a code for Plotting points (Scattered plot) (1,2), (2,7), (3,9), (4,1), (6,5), (7,10), (8,3).
3
Department of Engineering Mathematics, HKBKCE
Output:
2. Write a code to plot a line (Line plot) passing through the points (1, 2), (2, 7), (3, 9), (4, 1),
(6, 5), (7, 10), (8, 3).
4
Department of Engineering Mathematics, HKBKCE
Output:
Output:
5
Department of Engineering Mathematics, HKBKCE
Output:
Output:
6
Department of Engineering Mathematics, HKBKCE
Output:
Output:
7
Department of Engineering Mathematics, HKBKCE
Output:
5. Write a code to plot the equation of Folium of De-Cartes: 𝒙𝟑 + 𝒚𝟑 = 𝟑𝒂𝒙𝒚, take a=2
Output:
8
Department of Engineering Mathematics, HKBKCE
Output:
Output:
9
Department of Engineering Mathematics, HKBKCE
Output:
Output:
10
Department of Engineering Mathematics, HKBKCE
Output:
2. Write a code to plot parametric Equation of cycloid: 𝒙 = 𝒂(𝜽 − 𝐬𝐢𝐧 𝜽), 𝒚 = 𝒂(𝜽 − 𝒄𝒐𝒔𝜽)
take 𝒂 = 𝟐
from pylab import *
theta = linspace(-2*pi, 2*pi, 100)
a = 2
x = a*(theta-sin(theta))
y = a*(1-cos(theta))
plot(x,y)
show()
Output:
EXERCISE:
Plot the following :
1. Parabola 𝑦 2 = 4𝑎𝑥
𝑥2 𝑦2
2. Hyperbola − 𝑏2 = 1
𝑎2
6. Spiral of Archimedes: 𝑟 = 𝑎 + 𝑏𝜃
7. Limacon: 𝑟 = 𝑎 + 𝑏 cos 𝜃
11
Department of Engineering Mathematics, HKBKCE
1. Find the angle between the curves 𝒓 = 𝟒(𝟏 + 𝒄𝒐𝒔𝒕) and 𝒓 = 𝟓(𝟏 − 𝒄𝒐𝒔𝒕).
12
Department of Engineering Mathematics, HKBKCE
𝝅
1. Find the radius of curvature, 𝒓 = 𝟒(𝟏 + 𝒄𝒐𝒔𝒕) at 𝒕 = 𝟐 .
13
Department of Engineering Mathematics, HKBKCE
𝝅
2. Find the radius of curvature for 𝒓 = 𝒂𝒔𝒊𝒏(𝒏𝒕) at 𝒕 = and 𝒏 = 𝟏.
𝟐
(𝑎2 )1.5
Output: The radius of curvature is
2𝑎2
Output:
1 1.5
−𝑎 ( ) sin (𝑡)3
sin(𝑡)2
14
Department of Engineering Mathematics, HKBKCE
𝟑 𝟑
2. Find radius of curvature and curvature of 𝒙 = (𝒂 𝐜𝐨𝐬(𝒕)) ; 𝒚 = (𝒂 𝐬𝐢𝐧(𝒕))
𝟐 𝟐
EXERCISE
1. Find the angle between radius vector and tangent to the following polar curves
𝑎
a) 𝑟 = 𝑎𝜃 and 𝑟 = 𝜃
Ans: Angle between curves in radians is 90.000
b) 𝑟 = 2sin(𝜃) and 𝑟 = 2cos(𝜃)
Ans: Angle between curves in radians is 90.000
𝜋
2. Find the radius of curvature of 𝑟 = 𝑎(1 − cos(𝑡)) at 𝑡 = 2
1.5
0.942809041582063(𝑎2 )
Ans: 𝑎2
3. Find radius of curvature of 𝑥 = 𝑎cos3 (𝑡), 𝑦 = 𝑎sin3 (𝑡) at 𝑡 = 0.
Ans: 𝜌 = 0.75√3 and 𝜅 = 0.769800
𝜋
4. Find the radius of curvature of 𝑟 = 𝑎cos(𝑡) at 𝑡 = 4
1.5
(𝑎2 )
Ans: 2𝑎2
𝜋
5. Find the radius of curvature of 𝑥 = 𝑎(𝑡 − sin(𝑡)) and 𝑦 = 𝑎(1 − cos(𝑡)) at 𝑡 = 2 .
Ans: 𝜌 = 2.82842712 and 𝜅 = 0.353553
15
Department of Engineering Mathematics, HKBKCE
1. Prove that mixed partial derivatives, 𝒖𝒙𝒚 = 𝒖𝒚𝒙 for 𝒖 = 𝒆𝒙 (𝒙𝐜𝐨𝐬(𝒚) − 𝒚𝐬𝐢𝐧(𝒚)).
Output: Answer= 0
16
Department of Engineering Mathematics, HKBKCE
3.2. Jacobians
𝒙𝒚 𝒚𝒛 𝒛𝒙
1. If 𝒖 = ,𝒗= ,𝒘= then prove that 𝑱 = 𝟒.
𝒛 𝒙 𝒚
2. If 𝒖 = 𝒙 + 𝟑𝒚𝟐 − 𝒛𝟑 , 𝒗 = 𝟒𝒙𝟐 𝒚𝒛, 𝒘 = 𝟐𝒛𝟐 − 𝒙𝒚, then prove that at (𝟏, −𝟏, 𝟎), 𝑱 = 𝟐𝟎.
1 6𝑦 −3𝑧 2
[8𝑥𝑦𝑧 4𝑥 2 𝑧 4𝑥 2 𝑦 ]
−𝑦 −𝑥 4𝑧
𝛛(𝑿,𝒀,𝒁)
3. If 𝑿 = 𝝆𝐜𝐨𝐬(𝝓)𝐬𝐢𝐧(𝜽), 𝒀 = 𝝆𝐜𝐨𝐬(𝝓)𝐜𝐨𝐬(𝜽), 𝒁 = 𝝆𝐬𝐢𝐧(𝜽), then find .
𝛛(𝝆,𝝓,𝜽)
𝜌2 cos (∅)
Exercise
𝑦 ∂2 𝑢 ∂2 𝑢
1. 𝑢 = 𝑡𝑎𝑛−1 (𝑥 ). Verify that ∂𝑦 ∂𝑥 = ∂𝑥 ∂𝑦
Ans: True
(𝑥 2 +𝑦 2 )
2. If 𝑢 = log (𝑥+𝑦)
, show that 𝑥𝑢𝑥 + 𝑦𝑢𝑦 = 1
Ans: True
Ans: 𝑢𝑣
∂(𝑥,𝑦)
4. If 𝑥 = 𝑟cos(𝑡) and 𝑦 = 𝑟sin(𝑡), then find ∂(𝑟,𝑡) .
Ans: 𝐽 = 𝑟
∂(𝑢,𝑣,𝑤)
5. If u=𝑥 + 3𝑦 2 − 𝑧 3 , v=4𝑥 2 𝑦𝑧 and w=2𝑧 2 − 𝑥𝑦 , find at (-2,-1,1) .
∂(𝑥,𝑦,𝑧)
18
Department of Engineering Mathematics, HKBKCE
19
Department of Engineering Mathematics, HKBKCE
Output :
sin(100)= 0.984807753012208
2. Find the Maclaurin’s series expansion of 𝒔𝒊𝒏(𝒙) + 𝒄𝒐𝒔(𝒙) upto 𝟑𝒓𝒅 degree term, calculate
𝒔𝒊𝒏(𝟏𝟎∘ ) + 𝒄𝒐𝒔(𝟏𝟎∘ ).
from sympy import *
x=Symbol('x')
y=sin(x)+cos(x)
y1=diff(y,x)
y2=diff(y,x,2)
y3=diff(y,x,3)
yx=lambdify(x,y)
y1x=lambdify(x,y1)
y2x=lambdify(x,y2)
y3x=lambdify(x,y3)
x0=float(pi/2)
MS=yx(0)+x*y1x(0)+x**2*y2x(0)/2+x**3*y3x(0)/6
print("Maclaurin Series expansion is")
display(simplify(MS))
m=float(10*pi/180)
print("sin(10)+cos(10)=",yx(m))
20
Department of Engineering Mathematics, HKBKCE
Output:
Maclaurin Series expansion is
sin 𝒙
1. Evaluate lim𝒙→𝟎
𝒙
𝟓𝒙𝟒 −𝟒𝒙𝟐 −𝟏
2. Evaluate lim𝒙→𝟏
𝟏𝟎−𝒙−𝟗𝒙𝟑
𝟏 𝒙
3. Prove that lim𝒙→∞ (𝟏 + ) = 𝒆
𝒙
21
Department of Engineering Mathematics, HKBKCE
EXERCISE
1. Find the Taylor Series expansion of 𝑦 = 𝑒 −2𝑥 at 𝑥 = 0 upto third degree term.
Ans: 6
6. Evaluate lim𝑥→∞ √𝑥 2 + 𝑥 + 1 − √𝑥 2 + 1
Ans: 0.5
22
Department of Engineering Mathematics, HKBKCE
𝒅𝑷
1. Solve 𝒅𝒕
= 𝒓, 𝒓 = 𝟓, 𝑷(𝟎) = 𝟏 and plot the solution.
y
Output:
23
Department of Engineering Mathematics, HKBKCE
𝒅𝒚
2. Solve 𝒅𝒙 = −𝑲𝒚, 𝑲 = 𝟎. 𝟑, 𝒚(𝟎) = 𝟓 and plot the solution.
Output:
24
Department of Engineering Mathematics, HKBKCE
𝒅𝒚
3. Solve 𝒙𝟑 𝒅𝒙 − 𝒙𝟐 𝒚 + 𝒚𝟒 𝒄𝒐𝒔𝒙 = 𝟎, 𝒚(𝝅) = 𝟏 and plot the solution.
Output:
25
Department of Engineering Mathematics, HKBKCE
𝒅𝒚
4. Solve 𝒅𝒙 + 𝒚𝒕𝒂𝒏(𝒙) − 𝒚𝟑 𝒔𝒆𝒄(𝒙) = 𝟎, 𝒚(𝟎) = 𝟏 and plot the solution.
Output:
26
Department of Engineering Mathematics, HKBKCE
𝒅𝒚
5. Simulate 𝝉 𝒅𝒕 = −𝒚 + 𝑲𝒑; 𝑲𝒑 = 𝟑. 𝟎, 𝝉 = 𝟐. 𝟎 and 𝒚(𝟎) = 𝟏.
Output:
27
Department of Engineering Mathematics, HKBKCE
EXERCISE
1. Solve the following differential equations and plot the solution curves:
a. y sin x dx − (1 + 𝑦 2 + cos2x) dy = 0.
1 3 𝑦3
Ans: 2 𝑦cos2𝑥 + (2) 𝑦 + = 0.
3
𝑑𝑦
b. = 𝑥 + 𝑦 subject to condition 𝑦(0) = 2.
𝑑𝑥
Ans: y = 3ex − x − 1.
𝑑𝑦
c. = 𝑥 2 subject to condition y(0) = 5.
𝑑𝑥
𝑥3
Ans: y = + 5.
3
d. 𝑥 2 𝑦 ′ = y log(y) − 𝑦 ′
−1 𝑥
Ans: y(x) = 𝑒 𝐶1 𝑡𝑎𝑛
e. 𝑦 ′ − 𝑦 − 𝑥𝑒 𝑥 = 0.
𝑥2
Ans: y(x) = (C1+ )𝑒 𝑥
2
28
Department of Engineering Mathematics, HKBKCE
Euclidean Algorithm:
1. For 𝑎 > 𝑏, 𝑎 = 𝑏 × 𝑞 + 𝑟 (𝑏𝑦 𝑑𝑖𝑣𝑖𝑠𝑖𝑜𝑛 𝑎𝑙𝑔𝑜𝑟𝑖𝑡ℎ𝑚), where 0 ≤ 𝑟 < 𝑏
2. If r = 0, then GCD = b
3. If r ≠ 0, then assume 𝑎 = 𝑏 & 𝑏 = 𝑟 and repeat steps 1 to 3 until r = 0
1. Write a code to find the GCD of 614 and 124 by defining a new function using Euclidean
Algorithm
def gcdab(a,b):
r=1
if b<a:
a,b=b,a
while(r>0):
r=b%a
print(b,"=",a ,"x", b//a,"+",r)
b=a
a=r
continue
print('GCD =',b)
gcdab(614,124)
Output:
29
Department of Engineering Mathematics, HKBKCE
1. Write a code to check whether 163 and 512 are relatively prime
def rp(a,b):
r=1
a1,b1=a,b
if b<a:
a,b=b,a
while(r>0):
r=b%a
b=a
a=r
continue
if b==1:
print(f' {a1} and {b1} are relatively prime')
else:
print(f' {a1} and {b1} are not relatively prime')
rp(163,512)
def div(a,b):
r=1
a1,b1=a,b
if b<a:
a,b=b,a
while(r>0):
r=b%a
b=a
a=r
continue
if b==a1:
print(f' {a1} divides {b1} ')
else:
print(f' {a1} doesnot divides {b1}')
div(8,128)
30
Department of Engineering Mathematics, HKBKCE
Output:
EXERCISE
Ans: 6
2. What is the largest number that divides both 1024 and 1536?
Ans: 512
Ans: 4
31
Department of Engineering Mathematics, HKBKCE
Output:
enter integer a 6
enter integer b 5
enter integer m 15
the congruence has no integer solution
32
Department of Engineering Mathematics, HKBKCE
Output:
enter integer a 5
enter integer b 3
enter integer m 13
The 1 solutions are
x = 11(mod 13)
Output:
enter integer a 5
enter integer b 1
enter integer m 13
The 1 solutions are
x = 8(mod 13)
33
Department of Engineering Mathematics, HKBKCE
Output:
enter integer a 28
enter integer b 56
enter integer m 49
The 7 solutions are
x = 2(mod 49)
x = 9(mod 49)
x = 16(mod 49)
x = 23(mod 49)
x = 30(mod 49)
x = 37(mod 49)
x = 44(mod 49)
EXERCISE
Ans: 12
Ans: 21
3. Prove that 12𝑥 ≡ 7(𝑚𝑜𝑑14) has no solution. Give a reason for the answer.
34
Department of Engineering Mathematics, HKBKCE
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 𝜌(𝐴) = 𝑟 < 𝑛, then the system possesses (n-r) linearly
independent solutions.
Matrix ([[ row 1], [row 2], …, [row n]]) matrix ([[ row 1], [row 2], …, [row n]]) creates a m x n matrix .
A.shape [0], A.shape [1] A.shape [0], A.shape [1] gives the number of rows,
columns in matrix A respectively
1. Check whether the following system of homogenous linear equation has non-trivial
solution. 𝒙𝟏 + 2𝒙𝟐 − 𝒙𝟑 = 𝟎 , 𝟐𝒙𝟏 + 𝒙𝟐 + 𝟒𝒙𝟑 = 𝟎 , 𝟑𝒙𝟏 + 3𝒙𝟐 + 𝟒𝒙𝟑 = 𝟎
OUTPUT:
35
Department of Engineering Mathematics, HKBKCE
2. Check whether the following system of homogenous linear equation has non-trivial
solution 𝒙𝟏 + 2𝒙𝟐 − 𝒙𝟑 = 𝟎 , 𝟐𝒙𝟏 + 𝒙𝟐 + 𝟒𝒙𝟑 = 𝟎 , 𝒙𝟏 − 𝒙𝟐 + 𝟓𝒙𝟑 = 𝟎
OUTPUT:
36
Department of Engineering Mathematics, HKBKCE
1. Examine the consistency of the following system of equations and solve if consistent, also
plot the graphical solution. 𝒙𝟏 + 2𝒙𝟐 − 𝒙𝟑 = 𝟎 , 𝟐𝒙𝟏 + 𝒙𝟐 + 𝟒𝒙𝟑 = 𝟎 , 𝟑𝒙𝟏 +𝟑𝒙𝟐 + 𝟒𝒙𝟑 = 𝟎
OUTPUT:
The system has unique solution
[[ 7.]
[-4.]
[-2.]]
37
Department of Engineering Mathematics, HKBKCE
2. Examine the consistency of the following system of equations and solve and plot the
solution if consistent. 𝒙𝟏 + 2𝒙𝟐 − 𝒙𝟑 = 𝟎 , 𝟐𝒙𝟏 + 𝒙𝟐 + 𝟓𝒙𝟑 = 𝟎 , 𝟑𝒙𝟏 + 3𝒙𝟐 + 𝟒𝒙𝟑 = 𝟎
OUTPUT:
The system of equations is inconsistent
EXERCISE
𝑥 + 𝑦 + 𝑧 = 0, 2𝑥 + 𝑦 − 3𝑧 = 0, 4𝑥 − 2𝑦 − 𝑧 = 0
2. Find the solution of the non-homogenous system of equations
38
Department of Engineering Mathematics, HKBKCE
As we already know the def keyword is used to define a normal function in Python. Similarly,
the lambda keyword is used to define an anonymous function in Python
Syntax : lambda arguments : expression
Lambda function can have any number of arguments but only one expression, which is evaluated
and returned. It is efficient whenever one wants to create a function that only contains expressions
in a single line of a statement.
f1 = lambda x,y,z:(17-y+2*z)/20
f2 = lambda x,y,z:(-18-3*x+z)/20
f3 = lambda x,y,z:(25-2*x+3*y)/20
x0, y0, z0 = 0, 0, 0
e = float(input('Enter tolerable error : '))
print('\t Iteration \t x \t y \t z\n')
for i in range (0, 25):
x1 = f1(x0, y0, z0)
y1 = f2(x1, y0, z0)
z1 = f3(x1, y1, z0)
print('\t\t %d \t %0.4f \t %0.4f \t %0.4f\n' %(i, x1, y1, z1))
e1, e2, e3 = abs(x0-x1), abs(y0-y1), abs(z0-z1)
x0,y0,z0 = x1,y1,z1
if e1>e and e2>e and e3>e:
39
Department of Engineering Mathematics, HKBKCE
continue
else:
break
print('\n Solution : x = %0.3f , y = %0.3f and z = %0.3f\n'% (x1, y1, z1))
OUTPUT:
Enter tolerable error: 0.001
Iteration x y z
f1 = lambda x, y, z: (1+y-2*z)/3
f2 = lambda x, y, z: (3-x+z)/2
f3 = lambda x, y, z: (2-2*x+2*y)/6
x0, y0, z0 = 0, 0, 0
e = float(input('Enter tolerable error : '))
print('\t Iteration \t x\t y\t z\n')
for i in range(0, 25):
x1= f1(x0, y0, z0)
y1= f2(x1, y0, z0)
z1= f3(x1, y1, z0)
print('\t\t %d \t %0.4f \t %0.4f \t %0.4f \n' %(i, x1, y1, z1))
e1,e2,e3 = abs(x0-x1),abs(y0-y1),abs(z0-z1)
x0,y0,z0 = x1,y1,z1
if e1>e and e2>e and e3>e:
continue
else :
break
print('\n Solution : x = %0.3f, y = %0.3f and z = %0.3f\n'%(x1, y1, z1))
OUTPUT:
40
Department of Engineering Mathematics, HKBKCE
f1 = lambda x, y, z: (12-y-z)/10
f2 = lambda x, y, z: (12-x-z)/10
f3 = lambda x, y, z: (12-x-y)/10
x0, y0, z0 = 0, 0, 0
e = float(input('Enter tolerable error: '))
print('\t Iteration \t x \t y \t z \n')
for i in range (0, 25):
x1 = f1(x0, y0, z0)
y1 = f2(x1, y0, z0)
z1 = f3(x1, y1, z0)
print('\t\t %d \t %0.4f \t %0.4f \t %0.4f\n' %(i, x1, y1, z1))
e1,e2,e3 = abs(x0-x1), abs(y0-y1), abs(z0-z1)
x0,y0,z0 = x1,y1,z1
if e1>e and e2>e and e3>e:
continue
else :
break
print ('\n Solution: x = %0.3f, y = %0.3f and z = %0.3f\n'% (x1, y1, z1))
OUTPUT:
f1 = lambda x, y, z: (-3+y+z)/5
f2 = lambda x, y, z: (9+x+z)/5
f3 = lambda x, y, z: (15+2*x+y)/4
x0, y0, z0 = 0, 0, 0
e = float(input('Enter tolerable error: '))
print('\t Iteration \t x \t y \t z \n')
for i in range (0, 25):
x1 = f1(x0, y0, z0)
41
Department of Engineering Mathematics, HKBKCE
OUTPUT:
Enter tolerable error: 0.0001
Iteration x y z
EXERCISE
(ii) 𝑥 + 𝑦 + 𝑧 = 7, 2𝑥 + 𝑦 − 3𝑧 = 3, 4𝑥 − 2𝑦 − 𝑧 = −1
(i) 4𝑥 + 𝑦 + 𝑧 = 6, 2𝑥 + 5𝑦 − 2𝑧 = 5, 𝑥 − 2𝑦 − 7𝑧 = −8
(ii) 27𝑥 + 6𝑦 − 𝑧 = 85, 6𝑥 + 15𝑦 + 2𝑧 = 72, 𝑥 + 𝑦 + 54𝑧 = 110
42
Department of Engineering Mathematics, HKBKCE
OUTPUT:
Eigenvalues:
[8.98205672 2.12891771 0.88902557]
Eigenvectors:
[[-0.49247712 -0.82039552 -0.42973429]
[-0.26523242 0.14250681 -0.14817858]
[-0.82892584 0.55375355 0.89071407]]
𝟏 −𝟑 𝟑
2. Obtain the eigen values and eigen vectors for the given matrix (𝟑 −𝟓 𝟑)
𝟔 −𝟔 𝟒
OUTPUT:
Eigenvalues:
[ 4. -2. -2.]
43
Department of Engineering Mathematics, HKBKCE
Eigenvectors:
[[ 0.40824829 -0.40824829 -0.30502542]
[ 0.40824829 0.40824829 -0.808424 ]
[ 0.81649658 0.81649658 -0.50339858]]
𝟔 −𝟐 𝟐
1. Compute the numerically largest eigenvalue of P = [−𝟐 𝟑 −𝟏] by power method.
𝟐 −𝟏 𝟑
OUTPUT:
Eigenvalue: 7.999988555930031
Eigenvector:
[[ 1. ]
[-0.49999785]
[ 0.50000072]]
44
Department of Engineering Mathematics, HKBKCE
𝟏 𝟏 𝟑
2. Compute the numerically largest eigenvalue of P = [𝟏 𝟓 𝟏] by power method.
𝟑 𝟏 𝟏
OUTPUT:
Eigenvalue: 6.001465559355154
Eigenvector: [[0.5003663]
[1. ]
[0.5003663]]
EXERCISE
1. Find the eigenvalues and eigenvectors of the following matrices
25 1 2 11 1 2 3 1 1
25 1
a. P = [ ] b. P = [ 1 3 0] c. P = [ 0 10 0] d. P = [1 2 1]
1 3
2 0 −4 0 0 12 1 1 12
25 1 2
2. Find the dominant eigenvalue of the matrix P = [ 1 3 0 ]. Take 𝑋0 = (1, 0, 1)𝑇 .
2 0 −4
6 1 2
3. Find the dominant eigenvalue of the matrix P = [1 10 −1]. Take 𝑋0 = (1, 1, 1)𝑇 .
2 1 −4
5 1 1
4. Find the dominant eigenvalue of the matrix P = [1 3 −1] by power method.
2 −1 −4
45