Skip to content
Snippets Groups Projects
Commit e1d8a51e authored by Roger Wolf's avatar Roger Wolf
Browse files

adding tools

parent f93966d1
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:001d51ab-bdf8-40b5-9aad-54e33181e05c tags:
# Werkzeuge zur Datannahme für den Versuch Pendel
%% Cell type:markdown id:a7fd56cb-ed0a-4516-86e6-9fe10a9dd806 tags:
Mit den folgenden Code-Fragmenten zeigen wir Ihnen:
* Wie man die Daten Code-Zellen im Protokoll so vorbereiten kann, dass man während der Datrennahme per Hand die aufgenommenen Daten sofort graphisch darstellen kann.
* Wie man die $\chi^{2}$-Funktion aus dem Programmpaket `scipy` dazu verwenden kann einen $p$-Wert zu bestimmen.
Alle im Folgenden gezeigten Code-Fragmente lassen sich geeignet kombinieren.
%% Cell type:markdown id:4847bf0a-0697-400d-a0f0-11a41a48133b tags:
## Datenname per Hand und sofortige Visualierung der aufgezeichneten Daten im Protokoll
%% Cell type:markdown id:0928d73a-39a5-48fb-aa32-a3b5f881cca0 tags:
Mit dem folgenden Code-Fragment zeigen wir Ihnen:
* Wie man mit Hilfe der Programmpakete `numpy` und `matplotlib` und geschickter Vorbereitung der Code-Zellen im Protokoll Datenpunkte von Hand aufnehmen und während der Entstehung sofort graphisch darstellen kann.
%% Cell type:code id:b019dbde-bf4c-4db8-ba60-3cbdabfb2a10 tags:
``` python
import matplotlib.pyplot as plt
import numpy as np
from numpy import nan
# Check small angle approximation. Columns of entires are:
# phi0, T01, T02, T03, T04, T05;
# phi0 will run in steps of 5 deg von 60 bis 5 deg. Replace nan's by actual
# measurments
a = np.array([
60., nan, nan, nan, nan, nan,
55., nan, nan, nan, nan, nan,
50., nan, nan, nan, nan, nan,
45., nan, nan, nan, nan, nan,
40., nan, nan, nan, nan, nan,
35., nan, nan, nan, nan, nan,
30., nan, nan, nan, nan, nan,
25., nan, nan, nan, nan, nan,
20., nan, nan, nan, nan, nan,
15., nan, nan, nan, nan, nan,
10., nan, nan, nan, nan, nan,
5., nan, nan, nan, nan, nan,
]).reshape((12,6))
# Definition of a single measurement row (here done by using numpy)
phi0 = a[0:,0] # For each row --> the first column
T0 = a[0:,1:].mean(axis=1) # For each row --> the mean over columns 1... end
dT = a[0:,1:].std(axis=1,ddof=1) # For each row --> the standard deviation over columns 1 ... end
# Check whether the calculated vlaues mae sense
print("\n", phi0, "\n",T0, "\n", dT, "\n")
# Visualize the results; nan's wll be ignored to the figure will emerge point
# by point visualizing the progress of our data taking
plt.scatter(phi0, T0)
```
%% Cell type:markdown id:d7c21a7c-b21d-474a-8692-715e51386cd1 tags:
## Berechnung eines $p$-Werts auf Grundlage einer $\chi^{2}$-Verteilung
%% Cell type:markdown id:6b48a8c8-ffe3-484b-8434-0ffbc9006ece tags:
Mit dem folgenden Code-Fragment zeigen wir Ihnen:
* Wie man die $\chi^{2}$-funktion des Programmpakets `scipy` einließt und darstellt.
* Wie man mit Hilfe der kummulativen Verteilungsfunktion den $p$-Wert auf Grundlage einer $\chi^{2}$-Verteilung berechnet.
%% Cell type:code id:733f5ae8-799b-4daf-8155-9e803b2dc228 tags:
``` python
from scipy.stats import chi2
# The number of degrees of freedom
ndof=2
# Plot the PDF
x = np.linspace(chi2.ppf(0.01, ndof), chi2.ppf(0.99, ndof), 100)
plt.plot(x, chi2.pdf(x, ndof), color="darkblue", label=r"$\chi^{2}(x, 2)$")
plt.xlabel(r"$x$")
plt.ylabel(r"$\chi^{2}(x, 2)$")
plt.legend()
plt.show()
# Get the p-value from the CDF
print("The p-value for x=2.5 is:", 1.-chi2.cdf(2.5, ndof))
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment