Solhøyde oppg2
unknown
python
2 years ago
1.2 kB
18
Indexable
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
df = pd.read_csv('solhoyde-aal.csv',sep=';',comment='#',decimal='.')
Dag = df['Dag'].tolist()
Solhoyde = df ['Solhøyde'].tolist()
def T(t, a, k, c, d):
return a*np.sin(k*(t-c))+d
L, V = curve_fit(T, Dag, Solhoyde, p0 = (20,0.0001,100,12))
a, k, c, d = L
def f(x):
return a*np.sin(k*(x-c))+d
def f_derivert(x):
return a * k * np.cos(k * (x - c))
def f_dobbelderivert(x):
return -a * k**2 * np.sin(k * (x - c))
X = np.linspace(0, 350, 200)
plt.style.use('dark_background')
plt.figure(figsize=(10,5))
plt.scatter(Dag, Solhoyde, color="r", label=r'Plotting av reelle data')
plt.plot(X, f(X), label=r'Funksjonen $f(x)$ - regresjon', color = "white")
plt.plot(X, f_derivert(X), label=r"Funksjonen $f'(x)$", color = "blue")
plt.plot(X, f_dobbelderivert(X), label=r"Funksjonen $f''(x)$", color = "yellow")
plt.title(f"Solhøyde i løpet av et år\nGjennomsnittet er: {df['Solhøyde'].mean():.3f}")
plt.xlabel("Dag")
plt.ylabel("Høyde")
plt.legend()
plt.grid()
plt.show()
print(f"Verdiene: a = {a}\nk = {k}\nc = {c}\nd = {d}")Editor is loading...
Leave a Comment