import numpy as np
import matplotlib.pyplot as plt
from io import StringIO

# Daten
data1 = """
0.00 140.38
1.95 106.28
3.95 79.44
5.95 59.14
8.00 44.14
10.00 32.32
12.10 23.55
14.15 16.74
16.15 11.54
18.25 7.90
20.25 5.42

"""

data2 = """
0.00	141.12
1.95	104.40
3.95	76.32
5.95	57.60
8.00	43.20
10.00	30.96
12.10	21.60
14.15	15.84
16.15	11.52
18.25	7.20
20.25	4.32


"""

data3 = """
0	141.12
1.95	105.12
3.95	77.76
5.95	57.6
8	41.76
10	31.68
12.1	23.04
14.15	15.84
16.15	11.52
18.25	7.2
20.25	5.04


"""

# Daten in Arrays konvertieren
time, amplitude1 = np.genfromtxt(StringIO(data1), unpack=True)
_, amplitude2 = np.genfromtxt(StringIO(data2), unpack=True)
_, amplitude3 = np.genfromtxt(StringIO(data3), unpack=True)

# Halblogarithmischer Plot erstellen
plt.semilogy(time, amplitude1, 'bo', label='Computermessung')
plt.semilogy(time, amplitude2, 'g^', label='Messung 1 - Ablesen')
plt.semilogy(time, amplitude3, 'rs', label='Messung 2 - Ablesen')

# Lineare Regression für Daten 1
fit_params = np.polyfit(time, np.log(amplitude1), 1)
fit_line = np.exp(fit_params[1]) * np.exp(fit_params[0] * time)
plt.plot(time, fit_line, 'b--', label='')

# Lineare Regression für Daten 2
fit_params = np.polyfit(time, np.log(amplitude2), 1)
fit_line = np.exp(fit_params[1]) * np.exp(fit_params[0] * time)
plt.plot(time, fit_line, 'g--', label='')

# Lineare Regression für Daten 3
fit_params = np.polyfit(time, np.log(amplitude3), 1)
fit_line = np.exp(fit_params[1]) * np.exp(fit_params[0] * time)
plt.plot(time, fit_line, 'r--', label='')

plt.xlabel('Zeit in s')
plt.ylabel('Amplitude ')
plt.title('')
plt.grid(True)

plt.legend(loc='upper right')

plt.show()
# Lineare Regression für Daten 1
fit_params_1 = np.polyfit(time, np.log(amplitude1), 1)
fit_line_1 = np.exp(fit_params_1[1]) * np.exp(fit_params_1[0] * time)
slope_1, intercept_1 = fit_params_1
residuals_1 = np.log(amplitude1) - np.polyval(fit_params_1, time)
std_err_1 = np.sqrt(np.sum(residuals_1**2) / (len(amplitude1) - 2))
slope_std_1 = std_err_1 / np.sqrt(np.sum((time - np.mean(time))**2))
print("Steigung für Daten 1:", slope_1, "+/-", slope_std_1)

# Lineare Regression für Daten 2
fit_params_2 = np.polyfit(time, np.log(amplitude2), 1)
fit_line_2 = np.exp(fit_params_2[1]) * np.exp(fit_params_2[0] * time)
slope_2, intercept_2 = fit_params_2
residuals_2 = np.log(amplitude2) - np.polyval(fit_params_2, time)
std_err_2 = np.sqrt(np.sum(residuals_2**2) / (len(amplitude2) - 2))
slope_std_2 = std_err_2 / np.sqrt(np.sum((time - np.mean(time))**2))
print("Steigung für Daten 2:", slope_2, "+/-", slope_std_2)

# Lineare Regression für Daten 3
fit_params_3 = np.polyfit(time, np.log(amplitude3), 1)
fit_line_3 = np.exp(fit_params_3[1]) * np.exp(fit_params_3[0] * time)
slope_3, intercept_3 = fit_params_3
residuals_3 = np.log(amplitude3) - np.polyval(fit_params_3, time)
std_err_3 = np.sqrt(np.sum(residuals_3**2) / (len(amplitude3) - 2))
slope_std_3 = std_err_3 / np.sqrt(np.sum((time - np.mean(time))**2))
print("Steigung für Daten 3:", slope_3, "+/-", slope_std_3)

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: