Mathematics Using Python-Important Programs-CSE Stream
Mathematics Using Python-Important Programs-CSE Stream
1. Reporting Time:
2. Materials Required:
Bring your Lab IA answer booklet with the cover page duly filled.
Ensure you have your laptop in working condition.
Test Procedure:
1. Program Selection:
Each student must randomly pick a lot containing two programs, one from Part A and one from Part B.
Refer to the program list provided below.
2. Write-Up:
3.Execution:
4.Misconduct:
Method of Evaluation
1. Marks Distribution:
The Lab IA Test is conducted for 50 marks, which will be proportionally reduced to 10 marks for CIE.
The final Lab Assessment for CIE is 25 marks, split as:
DAM (15 marks)
Lab IA (10 marks)
3. Change of Question:
A student must score a minimum of 20 marks in Lab IA to become eligible for the Semester End Examination (SEE).
Part A
𝑥 2 𝑦2 𝑎 𝑏𝑎 √𝑎2−𝑥2
1. Find the area of an ellipse
𝑎2 + 𝑏2 = 1 by double integration [Take 𝑎 = 3 and 𝑏 = 2]. Hint: 𝐴 = 4 ∫0 ∫0 𝑑𝑦𝑑𝑥
In [1]: 1 from sympy import *
2 x,y=symbols('x y')
3 a=3
4 b=2
5 A=4*integrate(1,(y,0,(b/a)*sqrt(a**2-x**2)),(x,0,a))
6 display(A)
6.0𝜋
2. Find the area enclosed by the cardioid 𝑟 = 𝑎(1 + cos𝜃) above the initial line.
In [2]: 1 from sympy import *
2 r,t,a=symbols('r t a')
3 A=integrate(r,(r,0,a*(1+cos(t))),(t,0,pi))
4 display(A)
3𝜋𝑎2
4
𝑥 + 𝑦 + 𝑧 = 1, by using double
3. Find the volume of the tetrahendron bounded by the coordinate planes and the plane
integration.
𝑎 𝑏 𝑐
𝑉 = ∫ ∫ 𝑎 𝑐 (1 − 𝑥𝑎 − 𝑦𝑏 ) 𝑑𝑦𝑑𝑥
𝑎 𝑏(1− 𝑥 )
Hint:
0 0
In [3]: 1 from sympy import *
2 x,y,a,b,c=symbols('x y a b c')
3 V=integrate(c*(1-x/a-y/b),(y,0,b*(1-x/a)),(x,0,a))
4 display(V)
𝑎𝑏𝑐
6
4. Find gradient of 𝜙 = 𝑥2 𝑦𝑧
In [4]: 1 from sympy.vector import *
2 from sympy import symbols
3 N=CoordSys3D('N') #Setting the coordinate system
4 x,y,z=symbols('x y z')
5 A=N.x**2*N.y*N.z
6 print(f'\n Gradient of [A] is \n')
7 display(gradient(A))
Gradient of [A] is
2𝐱𝐍 2 𝐳𝐍 + 𝐲𝐍 2 − 6𝐲𝐍 𝐳𝐍
Curl of N.x*N.y**2*N.i + 2*N.x**2*N.y*N.z*N.j + (-3*N.y*N.z**2)*N.k is
0.000432900432900433 0.000432900432900433
beta and gamma are related
𝑑𝑦
𝑑𝑥 − 2𝑦 = 3𝑒 with 𝑦(0) = 0 using Taylor series method find 𝑦 at 𝑥 = 0.1,0.2,0.3 up to 4th degree terms.
2. Solve: 𝑥
y(0.10 ) is 1.11000
y(0.20 ) is 1.24205
𝑑𝑦 𝑦
4. Apply the Runge Kutta method to find the solution of
𝑑𝑥 = 1 + 𝑥 at 𝑦(2) taking ℎ = 0.2 , Given that 𝑦(1) = 2
In [9]: 1 from sympy import *
2 def RungeKutta( g , x0 , h , y0 , xn ):
3 x , y = symbols('x,y')
4 f = lambdify( [x , y] , g )
5 xt = x0 + h
6 Y = [y0]
7 while xt <= xn:
8 k1 = h * f( x0 , y0 )
9 k2 = h * f( x0 + h/2 , y0 + k1/2 )
10 k3 = h * f( x0 + h/2 , y0 + k2/2 )
11 k4 = h * f( x0 + h , y0 + k3 )
12 y1 = y0 + 1/6 * ( k1 + 2*k2 + 2*k3 + k4 )
13 Y.append( y1 )
14 print('y(%3.4f'%xt,') is %3.4f'%y1)
15 x0 = xt
16 y0 = y1
17 xt = xt + h
18 return Y
19 Y = RungeKutta( '1+y/x' , 1 , 0.2 , 2 , 2 )
y(1.2000 ) is 2.6188
y(1.4000 ) is 3.2710
y(1.6000 ) is 3.9520
y(1.8000 ) is 4.6580
y(2.0000 ) is 5.3863