summaryrefslogtreecommitdiffstats
path: root/fiz/vaje/10/tab.py
diff options
context:
space:
mode:
Diffstat (limited to 'fiz/vaje/10/tab.py')
-rwxr-xr-xfiz/vaje/10/tab.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/fiz/vaje/10/tab.py b/fiz/vaje/10/tab.py
index c5c24db..2b0bbae 100755
--- a/fiz/vaje/10/tab.py
+++ b/fiz/vaje/10/tab.py
@@ -1,7 +1,11 @@
#!/usr/bin/python3
import pandas
-import sys
+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"
@@ -9,6 +13,18 @@ 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);
-data = df.values
+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=",");
+ # df.to_csv("/dev/stdout", sep=argv[1][0]);
+ print(get_tikz_code(axis_width="0.75\\textwidth"))