### Andregrads 1
###

x = np.linspace(-1, 3, 200)
y = x**2 - 2*x

figure_begin()
plt.axhline(y=0, color = 'black') # Horisontal linje ved y = 0
plt.axvline(x=0, color = 'black') # Vertikal linje ved x = 0
plt.plot(x, y, color=(1,0.3,0.3))
plt.xlabel("x")
plt.ylabel("f(x)")

plt.grid()
figure_end()
figure_save("andregrads1")



###
### Graf 1
###

x = np.linspace(-1, 2, 200)
y = x**3 + x -1

figure_begin()
plt.axhline(y=0, color = 'black') # Horisontal linje ved y = 0
plt.axvline(x=0, color = 'black') # Vertikal linje ved x = 0
plt.plot(x, y, color=(0.4,0.4,1))
plt.xlabel("x")
###
### Motstand eksperiment
###

figure_begin()
data = np.loadtxt("datasett/motstand_eksperiment.txt")

spenning = data[:, 0]
strøm = data[:, 1]

plt.plot(spenning, strøm, "o")
plt.xlabel("Spenning (V)")
plt.ylabel("Strøm (A)")
figure_end()
figure_save("motstand_eksperiment")

###
### SAS-fly
###

figure_begin()
data = np.loadtxt("datasett/sas_fly.txt",
                  skiprows=1,
                  usecols=(1, 2, 3, 4, 5, 6))
navn = np.loadtxt("datasett/sas_fly.txt", skiprows=1, usecols=(0), dtype=str)

plt.barh(navn, data[:, 5])
plt.xlabel(
    "Drivstofforbruk $(\mathrm{liter} \cdot \mathrm{sete}^{-1} \cdot \mathrm{km}^{-1})$"
)
예제 #3
0
import numpy as np

from generate_figure_common import figure_begin, figure_end, figure_save

tid = [0, 15, 30, 45, 60, 90] # Tid i minutter
kontroll = [4.9, 5.1, 4.8, 4.3, 4.5, 4.7]
sukkerbrus = [4.5, 8.2, 9.5, 7.5, 5.4, 4.9]
eple = [4.6, 7.5, 9.2, 8.4, 6.4, 5.8]

###
### Blodsukker 1
###
figure_begin()
plt.plot(tid, kontroll) # Plotter kontrollverdiene mot tida
figure_end()
figure_save("blodsukker1")

###
### Blodsukker 2
###
figure_begin()
plt.plot(tid, kontroll) 
plt.title('Blodsukkermåling')       # Tittel på plottet
plt.xlabel('Tid (s)')               # Aksetittel på x-aksen
plt.ylabel('Blodsukkerkonsentrasjon (mmol/L)') # Aksetittel på y-aksen
plt.xlim(-10,100) # Definisjonsmengde
plt.ylim(-1,12)  # Verdimengde
plt.axhline(y=0, color = 'black') # Horisontal linje ved y = 0
plt.axvline(x=0, color = 'black') # Vertikal linje ved x = 0
plt.grid()
figure_end()
예제 #4
0
    b = 0.3 # Ns/m 
    g = 9.81
    
    for i in range(N-1):
        a = -m*g - b*v[i]
        v[i+1] = v[i] + a*dt 
        s[i+1] = s[i] + v[i]*dt + 0.5*a*dt**2 
        t[i+1] = t[i] + dt 
    
    plt.plot(t, s, "-o", label=r"$\Delta t = %.2f$" % dt)
plt.xlabel("Tid (s)")
plt.ylabel("Posisjon (m)")
plt.legend()

figure_end()
figure_save("rettlinjet_bevegelse")


###
### Ball med luftmotstand
###

def akselerasjon_skrått_kast(r, v, t):
    m = 0.15 
    b = 0.2 
    g = np.array([0, 9.81])
    return -m*g - b*np.sqrt(np.dot(v, v)) * v
    
dt = 0.01 
T = 4
N = int(T/dt)
    fder = (f(x + delta_x) - f(x)) / delta_x
    return fder


# Plotting
x = np.linspace(-2, 5, 1000)
y = f(x)
yder = numerisk_derivert(f, x, 1E-8)

plt.plot(x, y, color='green', label='f(x)')
plt.plot(x, yder, color='red', label='f\'(x)')
plt.xlabel('x')
plt.legend()
plt.grid()
figure_end()
figure_save("der_plott")

###
### Heistur
###

figure_begin()
# Leser av fila
data = np.loadtxt('datasett/heistur.csv', delimiter=',', skiprows=1)
t = data[:, 0]
h = data[:, 2]

# Derivasjonsvariabler
n = len(t)
v = np.zeros(n)
a = np.zeros(n)
###
### Linear spread
###

def f(x):
    return 4*x + 3
N = 100
x = np.linspace(0, 1, N)
y = f(x) + np.random.uniform(-1,1, N)

figure_begin()
plt.plot(x, y, "o")
plt.xlabel("x")
plt.ylabel("y")
figure_end()
figure_save("data_ml_linear")

###
### ML linear
###
import tensorflow as tf
from tensorflow.keras import layers

model = tf.keras.Sequential()
model.add(layers.Dense(1, activation="linear", input_shape=(1,)))

def loss(y, y_pred):
    return tf.math.reduce_mean((y-y_pred)**2)

model.compile(optimizer=tf.keras.optimizers.Adam(0.1),
              loss=loss)