summaryrefslogtreecommitdiffstats
path: root/fiz/vaje/10/tab.py
blob: 2b0bbae2eecdc36288eea9a5af0b7f9d9ac5202b (plain) (blame)
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
#!/usr/bin/python3
import pandas
from sys import argv, stderr
from math import pi
from numpy import sqrt, arange, argmax
from scipy.optimize import curve_fit
from matplotlib import pyplot
from tikzplotlib import get_tikz_code
l = 23.5
df = pandas.read_csv("podatki.tsv", sep="\t")
df.index.name = "idx"
df["x"] = (df["y"]/13*l)
df["omega"] = ((9.81/df["l"])**(1/2))
df["f"] = (df["omega"]*0.5/pi)
df = df.astype(float).round(6);
def objective(x, A, B, C):
	return A/sqrt((B**2-x**2)**2+C**2*x**2)
popt, _ = curve_fit(objective, df.values[:, 3], df.values[:, 2])
print(popt, file=stderr)
pyplot.scatter(df.values[:, 3], df.values[:, 2])
iksi = arange(min(df.values[:, 3]), max(df.values[:, 3]), 0.01)
ipsiloni = objective(iksi, popt[0], popt[1], popt[2])
print(f"omega nič je {iksi[argmax(ipsiloni)]}, kar je {iksi[argmax(ipsiloni)]/2/pi} Hz", file=stderr)
pyplot.plot(iksi, ipsiloni, "--", color="red")
pyplot.xlabel('$s_0 \\left[\\si{\\meter}\\right]$')
pyplot.ylabel('$\\omega=2\\pi\\nu$')
pyplot.title("$s_0\\left(\\omega\\right)$")
if __name__ == "__main__":
	# df.to_csv("/dev/stdout", sep=argv[1][0]);
	print(get_tikz_code(axis_width="0.75\\textwidth"))