Materialien/Piezokonstante_plot.py

52 lines
1.7 KiB
Python

import matplotlib.pyplot as plt
import numpy as np
k_L = 2e-10
spannung_10 = np.array([412, 284, 360, 548, 280, 304, 380, 312, 278, 444]) / 1000 / 2
spannung_20 = np.array([960, 960, 992, 968, 936, 952, 1160, 1200, 1010, 1000]) / 1000 / 2
spannung_50 = np.array([1180, 2020, 1120, 1260, 1240, 1580, 1140, 2340, 1700, 1060]) / 1000 / 2
spannung_100 = np.array([4080, 5280, 5160, 5080, 3520, 4280, 4800, 5120, 4400, 4240]) / 1000 / 2
ladung_10 = spannung_10 * k_L * 1e12 # Convert to pC
ladung_20 = spannung_20 * k_L * 1e12
ladung_50 = spannung_50 * k_L * 1e12
ladung_100 = spannung_100 * k_L * 1e12
gewichte = [10, 20, 50, 100]
ladungen = [ladung_10, ladung_20, ladung_50, ladung_100]
plt.figure(figsize=(10, 6))
for i, _ in enumerate(gewichte):
plt.scatter(np.full_like(ladungen[i], gewichte[i]), ladungen[i], color='royalblue')
mittelwerte = [np.mean(ladung) for ladung in ladungen]
plt.errorbar(gewichte, mittelwerte, yerr=np.std(ladungen, axis=1), fmt='o', color='fuchsia', label='Mittelwert ± Standardabweichung')
z = np.polyfit(gewichte, mittelwerte, 1) # Linear Regression
p = np.poly1d(z)
plt.plot(gewichte, p(gewichte), "r--", label='Bestgerade')
plt.xlabel('Gewicht m [g]')
plt.ylabel('Ladung Q [pC]')
plt.xticks(gewichte)
plt.xlim(5, 105)
plt.ylim(0, np.max(ladungen) * 1.1)
plt.legend(loc='upper left')
plt.grid(True)
plt.tight_layout()
plt.show()
#Mittelwerte
for i, mittelwert in enumerate(mittelwerte):
print(f"Mittelwert für Gewicht {gewichte[i]} g: {mittelwert:.2f} pC")
#Standardabweichung
for i, std in enumerate(np.std(ladungen, axis=1)):
print(f"Standardabweichung für Gewicht {gewichte[i]} g: {std:.2f} pC")
#Steigung und y-Achsenabschnitt der Bestgerade
print(f"Steigung der Bestgerade: {z[0]:.2f} pC/g")