-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise7_1_template.py
25 lines (20 loc) · 1.8 KB
/
exercise7_1_template.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
from ROOT import gRandom, TGraphErrors, TF1, TMath, TVirtualFitter, TCanvas, gStyle, TPaveStats, TGraph, Double, TFitResult
import numpy as np
nPoints = 20
data_x = np.array([ -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], dtype=np.float)
data_y = np.array([5.0935, 2.1777, 0.2089, -2.3949, -2.4457, -3.0430, -2.2731, -2.0706, -1.6231, -2.5605, -0.7703, -0.3055, 1.6817, 1.8728, 3.6586, 3.2353, 4.2520, 5.2550, 3.8766, 4.2890 ], dtype=np.float)
# define polynomials
P_2 = "[0] + [1]*x + [2]*x**2"
P_3 = "[0] + [1]*x + [2]*x**2 + [3]*x**3"
P_4 = "[0] + [1]*x + [2]*x**2 + [3]*x**3 + [4]*x**4"
P_5 = "[0] + [1]*x + [2]*x**2 + [3]*x**3 + [4]*x**4 + [5]*x**5"
P_6 = "[0] + [1]*x + [2]*x**2 + [3]*x**3 + [4]*x**4 + [5]*x**5 + [6]*x**6"
P_7 = "[0] + [1]*x + [2]*x**2 + [3]*x**3 + [4]*x**4 + [5]*x**5 + [6]*x**6 + [7]*x**7"
# define Legendre polynomials
L_2 = "[0] + [1]*x + [2]*0.5*(3.*x**2 - 1.)"
L_3 = "[0] + [1]*x + [2]*0.5*(3.*x**2 - 1.) + [3]*0.5*(5.*x**3 - 3.*x)"
L_4 = "[0] + [1]*x + [2]*0.5*(3.*x**2 - 1.) + [3]*0.5*(5.*x**3 - 3.*x) + [4]*0.125*(35.*x**4 - 30.*x**2 + 3.)"
L_5 = "[0] + [1]*x + [2]*0.5*(3.*x**2 - 1.) + [3]*0.5*(5.*x**3 - 3.*x) + [4]*0.125*(35.*x**4 - 30.*x**2 + 3.) + [5]*0.125*(63.*x**5 - 70.*x**3 + 15.*x)"
L_6 = "[0] + [1]*x + [2]*0.5*(3.*x**2 - 1.) + [3]*0.5*(5.*x**3 - 3.*x) + [4]*0.125*(35.*x**4 - 30.*x**2 + 3.) + [5]*0.125*(63.*x**5 - 70.*x**3 + 15.*x) + [6]*0.0625*(231.*x**6 - 315.*x**4 + 105.*x**2 - 5.)"
L_7 = "[0] + [1]*x + [2]*0.5*(3.*x**2 - 1.) + [3]*0.5*(5.*x**3 - 3.*x) + [4]*0.125*(35.*x**4 - 30.*x**2 + 3.) + [5]*0.125*(63.*x**5 - 70.*x**3 + 15.*x) + [6]*0.0625*(231.*x**6 - 315.*x**4 + 105.*x**2 - 5.) + [7]*0.0625*(429.*x**7 - 693.*x**5 + 315.*x**3 -35.*x)"
# --------------------------------------------------------------------