# Does NonlinearStateSpaceModel work with symbolic constants?

I'm trying to put a nonlinear system of two 2nd order ODEs given by:

eqs =
{2 (k1 + k2) q1[t] - 2 k2 q2[t] + 2 c1 Derivative[q1][t] +
2 c2 (Derivative[q1][t] - Derivative[q2][t]) +
l1 (g m2 Sin[q1[t]] + g m3 Sin[q1[t]] +
l2 m3 Sin[q1[t] - q2[t]] Derivative[q2][t]^2 +
l1 (m2 + m3) (q1^\[Prime]\[Prime])[t] +
l2 m3 Cos[q1[t] - q2[t]] (q2^\[Prime]\[Prime])[t]) ==
l1 f[t] Sin[q1[t] - q2[t]],
2 k2 q2[t] + 2 c2 (-Derivative[q1][t] + Derivative[q2][t]) +
l2 m3 (g Sin[q2[t]] -
l1 Sin[q1[t] - q2[t]] Derivative[q1][t]^2 +
l1 Cos[q1[t] - q2[t]] (q1^\[Prime]\[Prime])[t] +
l2 (q2^\[Prime]\[Prime])[t]) == 2 k2 q1[t]}


Into a nonlinear state space formulation, which I know can be done without linearization of 2nd order terms since

Solve[eqs, {q1''[t], q2''[t]}]


returns how to isolate these double slashed variables. However, when I try to

sys = NonlinearStateSpaceModel[
eqs, {q1[t], q2[t], q1'[t], q2'[t]}, {}, {q1[t], q2[t], q1'[t],
q2'[t]}, t]


to obtain $$\mathbf{\dot{x}} = f(\mathbf{x})$$ (that is, to make it a 4-row system of 1st order ODEs), it won't express it in terms of undefined $$m_{i},l_{i},k_{i},c_{i},g$$. If I end up defining these as numerical values, I can get the desired column vector ((4,1) matrix) even if the $$f(t)$$ in the first equation remains an undefined function of t.

I can't see why couldn't Mathematica handle the symbolic constants, since I suppose it would do almost the same algebraic manipulations.

Is it possible? Thanks in advance.

There appears to be two issues.

First, you need to specify $$f[t]$$ as an input.

Second, terms such as the ones below are not same.

SameQ[(q1^′′)[t], Derivative[q1][t]]


False

After those two fixes, you get an answer.

eqs = {2 (k1 + k2) q1[t] - 2 k2 q2[t] + 2 c1 Derivative[q1][t] +
2 c2 (Derivative[q1][t] - Derivative[q2][t]) +
l1 (g m2 Sin[q1[t]] + g m3 Sin[q1[t]] +
l2 m3 Sin[q1[t] - q2[t]] Derivative[q2][t]^2 +
l1 (m2 + m3) Derivative[q1][t] +
l2 m3 Cos[q1[t] - q2[t]] Derivative[q2][t]) ==
l1 f[t] Sin[q1[t] - q2[t]],
2 k2 q2[t] + 2 c2 (-Derivative[q1][t] + Derivative[q2][t]) +
l2 m3 (g Sin[q2[t]] -
l1 Sin[q1[t] - q2[t]] Derivative[q1][t]^2 +
l1 Cos[q1[t] - q2[t]] Derivative[q1][t] +
l2 Derivative[q2][t]) == 2 k2 q1[t]}

NonlinearStateSpaceModel[%, {q1[t], q2[t], q1'[t], q2'[t]}, {f[t]}, {q1[t], q2[t], q1'[t], q2'[t]}, t] • Tyvm! I ended up doing linear eigenvalue analysis of the system lol, but I guess the same problem would arrive while doing StateSpaceModel as well, which I'll be using in a short while – Petrini Oct 17 '19 at 14:50
• Should take only a couple of seconds :) Just delete 'Nonlinear' in NonlinearStateSpaceModel or wrap the result above in StateSpaceModel. – Suba Thomas Oct 17 '19 at 15:18