def sim(h, N, v_0, x_0): v = np.zeros(N) v[0] = v_0 x = np.zeros(N) x[0] = x_0 t = np.zeros(N) norm = np.zeros(N) fric = np.zeros(N) # Eulers shitty method for n in range(N - 1): # Update time and angle for current position t[n + 1] = t[n] + h alpha = exlab.slope(lane_h, x[n]) # Store current state for norm and fric norm[n] = fnorm(v[n], x[n], alpha) fric[n] = ffric(v[n], x[n], alpha) # Calculate next states for position and velocity x[n + 1] = x[n] + h * v[n] * np.cos(alpha) v[n + 1] = v[n] + 0.5 * h * fv(v[n], alpha) return t, v, x, norm, fric
def fix_exp_data(exp_data_t, exp_data_v, exp_data_x, FORMAT=False): # DIfferent parameters if format specified True if (not FORMAT): exp_x_offset = -0.05 exp_v_offset = 0.1 else: exp_x_offset = -0.05 exp_v_offset = 0 # Because v_exp is relative to the horizon and not the track, we need to change this for n in range(len(exp_data_v)): alpha = exlab.slope(lane_h, exp_data_x[n]) exp_data_v[n] *= np.cos(alpha) # Offset data to start at the origin exp_t_0 = exp_data_t[0] exp_x_0 = exp_data_x[0] exp_v_0 = exp_data_v[0] exp_data_v[0] = 0 for i in range(len(exp_data_t)): exp_data_t[i] -= exp_t_0 exp_data_x[i] -= exp_x_offset exp_data_v[i] -= exp_v_0 - exp_v_offset return exp_data_v, exp_data_x
def test_slope(self): x = np.array([-0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2]) y = x**2 h = height(x, y) y_interp = h(x) x_interp = np.linspace(0.2, 0.8, 100) dydx = 2 * x_interp angle = -np.arctan(dydx) s = slope(h, x_interp) if SHOW: from matplotlib import pyplot as plt fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.plot(x_interp, angle, 'x') ax.plot(x_interp, s) plt.show() self.assertTrue(np.allclose(s, angle, atol=0.01))
def get_time(x, y): he = height(x, y) x_interp = np.linspace(0.0, 1.4, 10000) alpha = slope(he, x_interp) kappa = curvature(he, x_interp) N = 10000 # antall steg h = 0.002 # stegstørrelse # initialverdier t_0 = 0 v_0 = 0 x_0 = 0 v_x_0 = 0 no_0 = 0 f_0 = 0 # konstant g/(1+(I_0/mr^2)) for kula K = 7.007143 m = 0.03 g = 9.81 c = 2 / 5 #kappa = curvature(he_acc, x_interp) # alpha funksjonen a(x) a = height(x_interp, alpha) k = height(x_interp, kappa) t = np.zeros(N + 1) v = np.zeros(N + 1) x = np.zeros(N + 1) v_x = np.zeros(N + 1) no = np.zeros(N + 1) f = np.zeros(N + 1) t[0] = t_0 v[0] = v_0 x[0] = x_0 v_x[0] = v_x_0 no[0] = no_0 f[0] = f_0 t_old = t_0 v_old = v_0 x_old = x_0 no_old = no_0 f_old = f_0 for n in range(N): v_new = v_old + h * (K * (np.sin(a(x_old)))) # Euler's method v_x_new = v_new * np.cos(a(x_old)) x_new = x_old + h * (v_new * np.cos(a(x_old))) aks = K * (np.sin(a(x_old))) f_new = m * g * np.sin(a(x_old)) - m * aks no_new = m * g * np.cos(a(x_old)) + m * v_new**2 / k(x_old) t[n + 1] = t_old + h v[n + 1] = v_new x[n + 1] = x_new v_x[n + 1] = v_x_new f[n + 1] = f_new no[n + 1] = no_new t_old = t_old + h v_old = v_new x_old = x_new if x_old >= 1.4: t_ans = t_old - h N = n break t = t[:N] x = x[:N] v_x = v_x[:N] f = f[:N] no = no[:N] return x, v, t_ans, t, v_x, f, no
import numpy as np import matplotlib.pyplot as plt from eksternlab import height, slope, curvature from scipy.constants import g x = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4] y = [0.472, 0.374, 0.313, 0.280, 0.284, 0.314, 0.373, 0.450] h = height(x, y) x_interp = np.linspace(0.0, 1.0, 50) alpha = slope(h, x_interp) kappa = curvature(h, x_interp) plt.plot(h, x_interp) plt.ylabel('$slope$'), plt.xlabel('$x$') plt.show()
from pylab import *;plot();show() x_track = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2] for i in range(len(x_track)): x_track[i] *= 0.975 y_track = [0.278, 0.151, 0.08, 0.055, 0.078, 0.151, 0.275] #Høydene vi målte på labben h = height(x_track, y_track) print("h:", h) x_interp = np.linspace(0.0, 1.2,50) #Er lengde fra til med antall intervaller print("x_interp:", x_interp, len(x_interp)) y_interp = h(x_interp) print("y_interp:", y_interp, len(y_interp)) alpha = slope(h, x_interp) #Hellingsvinkelen til banen kappa = curvature(h, x_interp) # Krumningsradiusen til banen. kappa[0] = kappa[1] for i in range(len(alpha)): print("x:", "{:1.3f}".format(x_interp[i]), "y:", "{:1.3f}".format(y_interp[i]), "Alfa:", "{:1.3f}".format(alpha[i]), "Kappa:", "{:1.3f}".format(kappa[i])) totaltid = 40 iterasjoner = 5000 a = [0] v = [0.5] s = [0] x = [0] f = [0]
atemp = 0 etemp = 0 rise = True m = 0.03 r = 0.011 k = 0.4 I = k*m*r*r gamma = -0.05222142975 #fra eksperiment c = -1*gamma * 2 * m * (1+k) numc = 3.75 * (10**(-6)) #teoretisk c print(f"Snittverdi for c: {c}\n") g = 9.81 fx = k*m pps = 1000 h = height(xxlist, hlist) alpha = (slope(h,xxlist[1])) avgA=0.3973574765 def accl(alpha, v): return (g*sin(alpha)-(c*v)/m)/(1 + k) start = time() # startverdier for å normalisere listelengde ntemp = m*vlist[0]*vlist[0]*curvature(h, xlist[0]) + m*g*cos(alpha) nlist.append(ntemp) ftemp = fx * accl(alpha, vlist[0]) flist.append(ftemp) atemp = accl(alpha, vlist[0]) alist.append(atemp)