<jupyter_start><jupyter_text>Systems identification Once you describe your system using differential equations, the next stage is to figure out the model parameters. Assume for example that you have a spring-damper-mass system (a physical system) whose behaviour can be described by![download.png](attachment:5ce883ad-6762-4bd7-b19d-17f3398a6fe7.png)$$m\ddot{x} + b\dot{x} + kx =  F(t),$$where $F(t)$ is the force applied to the mass.Demonstrate that the state equation for this system is $$\frac{dS(t)}{dt} = \left[\begin{array}{cc}0 & 1 \\-\frac{k}{m} & -\frac{b}{m}\end{array}\right]S(t) + \left[\begin{array}{cc}0  \\\frac{1}{m}\end{array}\right]F(t).$$and $$S(t) = \left[\begin{array}{c}x(t) \\\dot{x}(t)\end{array}\right].$$To study this system, you should find a way to measure $m$, $b$ and $k$. This can be done in multiple ways:- Disassemble the system and mesure each component separately :(- Use systems identification (SysID) to estimate the models parameters from data :)How to use SysID :1) Organize your system's equations to fit the format requiered by leas squares2) Perform one experiment and record the requiered data3) Use numerical methods to compute the requiered derivatives 4) Use least squares to determine the model parameters ExampleFor the mass-spring-damper system, we can re-write the equation as$$x(t) = -\frac{b}{k}\dot{x}(t) - \frac{m}{k}\ddot{x}(t) +  \frac{1}{k}F(t),$$we can write this equation as$$\left[\begin{array}{c}x(0) \\x(1) \\\vdots \\x(N)\end{array}\right] = \left[\begin{array}{ccc}\dot{x}(0) & \ddot{x}(0) & F(0) \\\dot{x}(1) & \ddot{x}(1) & F(1) \\\vdots & \vdots & \vdots \\\dot{x}(N) & \ddot{x}(N) & F(N) \\\end{array}\right] \left[\begin{array}{cc}-b/k \\-m/k \\1/k\end{array}\right]$$This equation can be solved for $b/m$, $k/m$, and $k$ using least squares if we know $x(t)$, $\dot{x}(t)$, $\ddot{x}(t)$, and $F(t)$.   Assume that you have the system (with unknown $m$, $b$, and $k$) and perform one experiment. Assume for simplicity that $F(t)=0$. You recorded the mass position $x(t)$ with a sampling interval of $h=0.01$s. Now, what to use that information to figure out the model parameters.<jupyter_code>#load the data
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn')

x = np.loadtxt('msd.txt')
h=0.01
fig, ax= plt.subplots(1,1,figsize = (5, 5), sharex=True)
ax.plot(np.arange(0,len(x))*h, x)
ax.set_xlabel('time')
ax.set_ylabel('Position')
ax.set_title('Mass Position')
plt.show()
#compure derivatives using numerical methods



dx = np.gradient(x, h)
ddx = np.gradient(dx, h)


#solve the least squares problem 
from scipy.linalg import lstsq
M= np.column_stack((dx,ddx))
p, res, rnk, s = lstsq(M,x)
print(f'The resulting coeficients are \n -b/k = {p[0]} \n -m/k = {p[1]}')<jupyter_output>The resulting coeficients are 
 -b/k = -0.16017949545102858 
 -m/k = -0.20136337344389307
{'fraction_non_alphanumeric': 0.17620376831821355, 'fraction_numerical': 0.030704815073272853, 'mean_word_length': 4.66600790513834, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '643223', 'license': 'MIT', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1030, 'n_words': 322, 'path': 'SysID.ipynb', 'repo_name': 'dguari1/BME3240_2021', 'size': '2866'}