<jupyter_start><jupyter_text>$m \ddot{x} + c \dot{x} +kx=u$ $\vec{x} = \begin{bmatrix} x \\ \dot{x} \end{bmatrix}$ $\vec{u} = \begin{bmatrix} u \end{bmatrix}$ $\vec{y} = \begin{bmatrix} x \end{bmatrix}$ $\ddot{x} = (-c \dot{x} -kx + u)/m$ $\dot{\vec{x}} = \begin{bmatrix} \dot{x} \\ (-c \dot{x} -kx + u)/m \end{bmatrix}$<jupyter_code>m = ca.SX.sym('m')
c = ca.SX.sym('c')
k = ca.SX.sym('k')
p = ca.vertcat(m,c,k)
u = ca.SX.sym('u')
xvec = ca.SX.sym('x', 2)
x = xvec[0]
xdot = xvec[1]

# or,
''' 
x = ca.SX.sym('x')
xd = ca.SX.sym('xd') 
'''

xv_dot = ca.vertcat(xdot, (-c*xdot - k*x + u)/m)
xv_dot
f_rhs = ca.Function('rhs', [xvec, u, p], [xv_dot], ['x','u','p'],['x_dot'], {'jit':True})
f_rhs
f_rhs([1,2],[0],[1,2,3])
import scipy.integrate
import numpy as np
scipy.integrate.solve_ivp(fun = lambda t, x: np.array(f_rhs(x, 1, [1,2,3])).reshape(-1), t_span=[0,1], y0 =[0,0], t_eval=np.arange(0,1,0.1))
plt.plot(res['t'],res['y'][0,:]);
A = ca.jacobian(xv_dot, xvec)
A<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.30190571715145437, 'fraction_numerical': 0.024072216649949848, 'mean_word_length': 4.453551912568306, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '511758', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 542, 'n_tokens_neox': 530, 'n_words': 90, 'path': 'lectures/casadi_practice.ipynb', 'repo_name': 'jjffkkgg/aae497-f19', 'size': '997'}