import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import CubicSpline
h = 200
xfast=np.asarray([0,1,2,3,4,5,6,7])*h
xmin = 0
xmax = 1401
dx = 1
x = np.arange(xmin,xmax,dx)
#Skruehøyder:
yfast = np.zeros(8)
yfast[0] = 300
yfast[1] = 246
yfast[2] = 165
yfast[3] = 162
yfast[4] = 214
yfast[5] = 198
yfast[6] = 128
yfast[7] = 96
cs = CubicSpline(xfast,yfast,bc_type='natural')
y = cs(x)
dy = cs(x,1)
d2y = cs(x,2)
import csv
header = []
data = []
filename = 'fysikklab.csv'
with open(filename) as csvfile:
csvreader = csv.reader(csvfile)
header = next(csvreader)
for datapoint in csvreader:
values = [float(value) for value in datapoint]
data.append(values)
time = [(p[0]) for p in data]
fart = [(p[3]*1000) for p in data]
pos_x = [(p[1]*1000) for p in data]
pos_y = [(p[2]*1000) for p in data]
posisjonsutvilking = plt.figure('Posisjon',figsize=(12,6))
plt.plot(x,y, label = 'Numerisk')
plt.plot(pos_x, pos_y, label = 'Eksperimentell')
plt.title('Posisjonen til kulen')
plt.xlabel('posisjon i x-retning (mm)')
plt.ylabel('posisjon i y-retning (mm)')
plt.grid()
plt.legend()
plt.show()
Run to view results
βR = np.arctan(dy)
β = np.degrees(βR)
helningsvinkel = plt.figure('β',figsize=(12,6))
plt.plot(x,β)
plt.title('Banens helningsvinkel', fontsize=20)
plt.xlabel('$x$ (mm)',fontsize=20)
plt.ylabel('$β$ (grader)',fontsize=20)
plt.ylim(-30,30)
plt.xlim(-50,1450)
plt.grid()
plt.show()
Run to view results
g = 9810
c = 2/5
m = 0.031
v = np.sqrt((2*g*(y[0] - y))/(1+c))
K = d2y/(1+dy**2)**(1.5)
a = v**2 * K
N = m * (g/1000 * np.cos(βR) + a/1000)
normalkraft = plt.figure('N(x)',figsize=(12,6))
plt.plot(x,N)
plt.title('Normalkraften', fontsize=20)
plt.xlabel('$x$ (mm)',fontsize=20)
plt.ylabel('$N(x)$ (N)',fontsize=20)
plt.ylim(0,0.80)
plt.xlim(-50,1450)
plt.grid()
plt.show()
Run to view results
f = 2*m*(g/1000)*np.sin(βR)/7
friksjonsform = plt.figure('f(x)',figsize=(12,6))
plt.plot(x,f)
plt.title('Kulens friksjon', fontsize=20)
plt.xlabel('$x$ (mm)',fontsize=20)
plt.ylabel('$f(x)$ (N)',fontsize=20)
plt.ylim(-0.2,0.2)
plt.xlim(-50,1450)
plt.grid()
plt.show()
Run to view results
forhold = plt.figure('Forholdet $|f/N|$',figsize=(12,6))
plt.plot(x,np.abs(f/N))
plt.title('Forholdet |f/N|', fontsize=20)
plt.xlabel('$x$ (mm)',fontsize=20)
plt.ylabel('$|f/N|$',fontsize=20)
plt.ylim(0,0.15)
plt.xlim(-50,1450)
plt.grid()
plt.show()
Run to view results
fartentilkulen = plt.figure('Farten til kulen',figsize=(12,6))
v = np.sqrt((2*g*(y[0] - y))/(1+c))
plt.plot(x,v, label = 'Numerisk')
plt.plot(pos_x, fart, label = 'Eksperimentell')
plt.title('Farten til kulen')
plt.xlabel('posisjon i x-retning (mm)')
plt.ylabel('fart (mm/s)')
plt.legend()
plt.grid()
plt.show()
Run to view results
header = []
data = []
filename = 'fysikklab.csv'
with open(filename) as csvfile:
csvreader = csv.reader(csvfile)
header = next(csvreader)
for datapoint in csvreader:
values = [float(value) for value in datapoint]
data.append(values)
time = [(p[0]) for p in data]
fart = [(p[3]*1000) for p in data]
pos_x = [(p[1]*1000) for p in data]
pos_y = [(p[2]) for p in data]
t = np.zeros(len(x))
n = 1401
for j in range(1, n):
deltat_n = 2*dx/ (v[j]*np.cos(βR[j]) + v[j-1]*np.cos(βR[j-1]))
t[j] = t[j-1] + deltat_n
tidsutvikling = plt.figure('Tidsutvikling',figsize=(12,6))
plt.title('Tidsutvikling')
plt.xlabel('t(s)')
plt.ylabel('y(t)(m)')
plt.plot(t,y/1000, label = 'Numerisk')
plt.plot(time, pos_y, label = 'Eksperimentell')
plt.legend()
plt.grid()
plt.show()
Run to view results