import matplotlib.pyplot as plt
import numpy as np
import math
t = np.linspace(0,20,2000) #betwixt 0,4, 2k points
def a(m,k,g): # to test +ve / 0s
return (g**2 - 4*m*k)
def x(m,k,g,t):
return math.exp(((-g-math.sqrt(abs(g**2-4*m*k)))/2*m)*t) #taking the -ve sqrt,
xv = np.vectorize(x) # ? should learn about python
this is the overdamped case,
print('a is', a(0.1,0.1,1)) # +ve
O = xv(0.1,0.1,1,t)
print(O)
plt.plot(t, O)
print('a is', a(1,1,0)) #-ve
N = xv(1,1,0,t)
print(N)
plt.plot(t, N)
this represents critical damping
print('a is', a(1,1,2)) #0
Z = xv(1,1,2,t)
print(Z)
plt.plot(t, Z)
plt.plot(t,N,Z)
particular
freq = np.linspace(0,2,2000)
A = 1 / (-freq*freq+freq*0.1j+1) # imaginary numbs in py: num_j 0.1j here, fancy!
plt.plot(freq,np.absolute(A)) # np can pull real (absolute?) or phase (angle) from imaginary
plt.plot(freq,np.angle(A))
A = [[2,-1],
[-1,2]] #numpy matricies: row-order nd arrays
print(A)
D = np.linalg.eig(A)
print(D)
print(math.sqrt(1/2)) #looks like,
to start, I'm going to hit this and plot it,
def filter(alpha, sig, result):
for i in range(sig.size-1) :
result[i] = alpha*result[i - 1] + (1-alpha)*sig[i] #easier to not-step underneath arr,
series = 100
S = np.zeros(series)
S[10] = 1
S[16] = 1
R = np.zeros(series)
filter(0.7, S, R)
plt.plot(S)
plt.plot(R)