-
Notifications
You must be signed in to change notification settings - Fork 1
/
Session 1.py
128 lines (96 loc) · 2.52 KB
/
Session 1.py
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import math
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
import plotly.graph_objects as go
# Task 1
a = np.arange(-5,-1.5,0.5)
b = np.arange(-1.95,3,0.05)
c = np.arange(3,5.5,0.5)
x = np.concatenate((a,b,c))
f, g = [], []
for i in range(x.size):
f.append(math.sin(x[i]))
g.append(math.sin((x[i])**2+np.pi))
#fig, ax = plt.subplots()
#ax.scatter(x, y_1, color='red', marker='d')
#ax.scatter(x, y_2, color='purple', marker='o')
#plt.show()
#Task 2
dx = 0.1#*np.pi
x = np.arange(-2*np.pi,2*np.pi+dx,dx)
y = np.arange(-np.pi,2*np.pi+dx,dx)
Nx = len(x)
Ny = len(y)
Xg, Yg = np.meshgrid(x, y)
F = np.sin(Xg)*np.cos(Yg) # element-wise operation using meshgrid
G = np.cos(Xg)*np.sin(Yg)
S = F + G
P = F * G
print(P[2,10])
#Task 3
# Comment away the others to show a particular graph
#ax = plt.axes(projection='3d') # comment this away for contour plots
#ax.plot_surface(Xg,Yg,S)
#ax.plot_surface(Xg,Yg,P)
#plt.contour(Xg,Yg,S)
#plt.contour(Xg,Yg,P)
#plt.show()
R = F * np.e**(-0.5*0)
#ax.plot_surface(Xg,Yg,R)
R = F * np.e**(-0.5*5)
#ax.plot_surface(Xg,Yg,R)
#plt.show()
t = np.arange(0,10.05,0.05)
R_spec = np.sin(np.pi)*np.cos(-np.pi/2)*np.e**(-0.5*t)
#plt.scatter(t,R_spec)
#plt.show()
#Task 4
dl = 0.5
l = np.arange(-5,5+dl,dl)
Xg, Yg = np.meshgrid(l, l)
f_1i, f_1j = Xg, Yg
f_2i, f_2j = Yg, -Xg
#plt.quiver(Xg,Yg,f_1i,f_1j)
#plt.streamplot(Xg,Yg,f_1i,f_1j)
#plt.quiver(Xg,Yg,f_2i,f_2j)
#plt.streamplot(Xg,Yg,f_2i,f_2j)
#plt.show()
#f_1 is irrotational with positive divergence everywhere, f_2 is rotational with no divergence everywhere
#Task 5
c = open("Computing.txt", "r")
m = open("Maths.txt", "r")
c_read = c.readlines()
m_read = m.readlines()
c_marks = []
m_marks = []
for item in c_read:
c_marks.append(int(float(item.rstrip())))
for item in m_read:
m_marks.append(int(float(item.rstrip())))
c_values, c_counts = np.unique(c_marks, return_counts=True)
m_values, m_counts = np.unique(m_marks, return_counts=True)
#plt.bar(c_values, c_counts)
#plt.bar(m_values, m_counts)
#plt.scatter(c_marks,m_marks)
#plt.xlabel("Computing Marks")
#plt.ylabel("Maths Marks")
#plt.show()
d = 0.1 #*np.pi
x = np.arange(-2,2+d,d)
y = np.arange(-3,3+d,d)
z = np.arange(-np.pi,2*np.pi+d,d)
Xg, Yg, Zg = np.meshgrid(x,y,z)
F = Xg**2 + Yg**2 + Zg**2 - 5*np.sin(Zg)**2
fig = go.Figure(data=go.Isosurface(
x=Xg.flatten(),
y=Yg.flatten(),
z=Zg.flatten(),
value=F.flatten(),
isomin=1,
isomax=10,
surface_count=5,
opacity=0.6,
caps=dict(x_show=False, y_show=False)
))
fig.show()