Given a dynamic system, \begin{equation*} \frac{d\vec{s}}{dt}=f(t,\vec{s},\vec{c}) \end{equation*} where $\vec{s}$ are the state, and $\vec{c}$ are constants.
And $\vec{s_0},\vec{s_1},...\vec{s_n}$ for $t_0,t_1,...t_n$, assume $n>>$ dimension of $\vec{s}$ and $\vec{c}$
- How do find $\vec{c}$ numerically?
- Is it even possible?
I assume you can just use least_square to solve for those constants since the number of sample data point is way bigger than than the number of constant needed to be solve.
To test that, I solve for the ivp of the system and try to apply least square but it doesn't works
for a simple example, $\vec{s}=[\theta\quad\omega]^T$
\begin{align*} \frac{d\theta}{dt} &= \omega\\ \frac{d\omega}{dt} &= C_0[\sin(t)-\theta] \end{align*}
to model it with python
import numpy
def construct_state_space_eq(C_0):
def state_space_eq(t,x):
return [
x[1],
C_0 * (np.sin(t)-x[0])
]
return state_space_eq
and solve the ivp
import scipy
start = 0
end = 10
sol = scipy.integrate.solve_ivp(
construct_state_space_eq(100),
[start,end],
[0,0],
max_step=0.001
)
and to retrieve data from solution
time = sol.t
angle = sol.y[0]
speed = sol.y[1]
accel = np.diff(angle)/np.diff(time)
accel = np.array([*accel,accel[-1]])
and then define the error to minimize
def dyn(x):
C_0, = x
lhs = np.array([speed, accel])
rhs = construct_state_space_eq(C_0)(time,[angle,speed])
return np.sum(np.square(lhs - rhs),axis=0)
and try to minimize the error
guess = [100] # the actual C_0
sol = scipy.optimize.least_squares(
dyn,
guess,
bounds=[0,1000]
)
print(sol.x) # array([0.22989073]) <= but it should be 100
but the result is way off, no matter what the initial guess is.
Is there something fundamentally wrong with my assumption?

lhsis $\begin{bmatrix}\omega \ \alpha\end{bmatrix}$, andrhsis $\frac{d}{dt} \begin{bmatrix}\theta \ \omega\end{bmatrix}$, both calculated fromsolve_ivp, so they should amount to the sameC_0, isn't it? – 啊鹿Dizzyi Sep 22 '23 at 02:30