-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLab-1.py
More file actions
103 lines (81 loc) · 2.48 KB
/
Lab-1.py
File metadata and controls
103 lines (81 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""Converted from Lab-1.ipynb"""
# 1. Evaluate the integral ∫01 ∫0x(x2 + y2)dydx
from sympy import *
x,y,z=symbols('x y z')
w1=integrate(x**2+y**2,(y,0,x),(x,0,1))
print(w1)
# 2. Evaluate the integral ∫03 ∫03−x ∫03−x−y(xyz)dzdydx
from sympy import *
x,y,z=symbols('x y z')
w2=integrate((x*y*z),(z,0,3-x-y),(y,0,3-x),(x,0,3))
print(w2)
# 3. Prove that ∫ ∫ (x2 + y2)dydx = ∫ ∫ (x2 + y2)dxdy
from sympy import *
x,y,z=symbols('x y z')
w3=integrate(x**2+y**2,y,x)
pprint(w3)
w4=integrate(x**2+y**2,x,y)
pprint(w4)
# 4. Find the area of an ellipse by double integration. A=4 ∫0a ∫0(b/a)√a2−x2dydx
from sympy import *
x=Symbol('x')
y=Symbol('y')
a=4
b=6
w3=4*integrate(1,(y,0,(b/a)*sqrt(a**2-x**2)),(x,0,a))
print(w3)
# 5. Find the area of the cardioid r = a(1 + cosθ) by double intgration.
from sympy import *
r=Symbol('r')
t=Symbol('t')
a=Symbol('a')
w3=2*integrate(r,(r,0,a*(1+cos(t))),(t,0,pi))
pprint(w3)
# 6. Find the volume of the tetrahedron bounded by the planes and , x/a+y/b+z/c=1
from sympy import *
x,y,z,a,b,c=symbols('x y z a b c')
w2=integrate(1,(z,0,c*(1-x/a-y/b)),(y,0,b*(1-x/a)),(x,0,a))
print(w2)
# 7. Find the center of gravity of cardioid . Plot the graph of cardioid and mark the center of gravity
import numpy as np
import matplotlib.pyplot as plt
import math
from sympy import *
r = Symbol('r')
t = Symbol('t')
a = Symbol('a')
I1 = integrate(cos(t)*r**2, (r, 0, a*(1+cos(t))), (t, -pi, pi))
I2 = integrate(r, (r, 0, a*(1+cos(t))), (t, -pi, pi))
I = I1/I2
print(I)
I = I.subs(a, 5)
plt.axes(projection='polar')
a = 5
rad = np.arange(0, (2 * np.pi), 0.01)
# plotting the cardioid
for i in rad:
r = a + (a*np.cos(i))
plt.polar(i, r, 'g.')
plt.polar(0, I, 'r.')
plt.show()
# E1. evaluate ∫₀¹ ∫₀ˣ (x + y) dy dx
from sympy import symbols, integrate
x, y = symbols('x y')
integral_result = integrate(x + y, (y, 0, x), (x, 0, 1))
print(integral_result)
# E2. ∫₀ˡᵒᵍ(2) ∫₀ˣ ∫₀ˣ⁺ˡᵒᵍ(y) eˣ⁺ʸ⁺ᶻ dz dy dx
from sympy import *
x,y,z=symbols('x y z')
w2=integrate(exp(x*y*z),(z,0,log(y)),(y,0,x),(x,0,log(2)))
print(w2)
# E3. Find the area of positive quadrant of the circle x2 + y2 = 16
from sympy import *
x = Symbol('x')
y = Symbol('y')
A = integrate(1, (y, 0, sqrt(16 - x**2)), (x, 0, 4))
print(A)
# E4. Find the volume of the tetrahedron bounded by the planes x=0, y=0 and z =0, x/2+y/3 +z/4= 1
from sympy import *
x, y, z = symbols('x y z')
V = integrate(1, (z, 0, 4*(1 - x/2 - y/3)), (y, 0, 3*(1 - x/2)), (x, 0, 2))
print(V)