Skip to content

Commit 8bc1951

Browse files
Add files via upload
1 parent 3457540 commit 8bc1951

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import numpy as np
2+
from scipy import optimize
3+
import matplotlib.pyplot as plt
4+
5+
np.random.seed(0)
6+
7+
# Our test function
8+
def f(t, omega, phi):
9+
return np.cos(omega * t + phi)
10+
11+
# Our x and y data
12+
x = np.linspace(0, 3, 50)
13+
y = f(x, 1.5, 1) + .1*np.random.normal(size=50)
14+
15+
# Fit the model: the parameters omega and phi can be found in the
16+
# `params` vector
17+
params, params_cov = optimize.curve_fit(f, x, y)
18+
19+
# plot the data and the fitted curve
20+
t = np.linspace(0, 3, 1000)
21+
22+
plt.figure(1)
23+
plt.clf()
24+
plt.plot(x, y, 'bx')
25+
plt.plot(t, f(t, *params), 'r-')
26+
plt.show()

0 commit comments

Comments
 (0)