-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Exam
More file actions
94 lines (56 loc) · 1.83 KB
/
Python Exam
File metadata and controls
94 lines (56 loc) · 1.83 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
#%% Loading txt
import numpy as np
# loading .txt or other file
data = np.loadtxt() # using delimiters
#%% Lineal Regression
from scipy import stats
linregress = stat.linregress(x_array, y_array) # It returns more than one variables: slope, intercept, rvalue
plt.plot(x_array, linregress.intercept + linregress.slope*dia[100:226], 'b', label='recta')
#%% Optimize Curve fit with a analytical function
Topt, Tcov = optimize.curve_fit(func, x, y)
#%% Finding max and min techniques
sr_res = np.abs(res[:, 2]-res[:,3])
sr_min = np.amin (sr_res)
idx_sr = np.where(sr_res == sr_min)
i_idxmax = np.argmax(res[:, 0])
imax = res[:, 0][i_idxmax]
frac = imax/1 * 100
#%% Sumatorio
N = len(txt)
Tref = 2.714
MSE = 0
for i in range(0, N):
MSE += (datos[1][i] - rad(datos[0][i], Tref))*(1/N)
#%% Integration Techniques
from scipy import integrate
res = integrate.quad(func, lower limit, upper limit) # returns the value and the error
x = np.array([])
y = np.array([])
res = integrate.simpson(x, y)
#%% Differential Equation
from scipy import integrate
# Every index and eds should be in order
def func(x,t):
return ...
ci = np.array([])
t = np.linspace(..., ..., ...)
res = integrate.odeint(func, ci, t)
#%% 2D array representation with function
# 1 variable
sigma = 0.15
n = 500
# coordenada radial
xx, yy = np.linspace (-1, 1, n), np.linspace(-1, 1, n)
X,Y = np.meshgrid(xx,yy[::-1])
r = np.sqrt(X**2 + Y**2)
s= lambda r: (1- (r**2)/(2* sigma**2)) * np.exp(-r**2/(2* sigma**2))
plt.imshow(s(r), cmap = 'rainbow', extent = [-1, 1, -1, 1])
plt.colorbar()
# 2 variables
xx, yy = np.linspace (-1, 1, 501), np.linspace (-1, 1, 501)
X, Y = np.meshgrid(xx, yy)
G2 = lambda X, Y: np.exp(-(X**2 + Y**2 * gamma**2)/(2 * sigma**2)) * np.cos(2*np.pi*X/l)
plt.subplot(1, 2, 2)
plt.grid(True)
plt.imshow(G2(X,Y), cmap = 'nipy_spectral')
plt.colorbar()