2
$\begingroup$

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[1][q1][t] + 
   2 c2 (Derivative[1][q1][t] - Derivative[1][q2][t]) + 
   l1 (g m2 Sin[q1[t]] + g m3 Sin[q1[t]] + 
      l2 m3 Sin[q1[t] - q2[t]] Derivative[1][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[1][q1][t] + Derivative[1][q2][t]) + 
   l2 m3 (g Sin[q2[t]] - 
      l1 Sin[q1[t] - q2[t]] Derivative[1][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.

$\endgroup$

1 Answer 1

2
$\begingroup$

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[2][q1][t]]

False

After those two fixes, you get an answer.

eqs = {2 (k1 + k2) q1[t] - 2 k2 q2[t] + 2 c1 Derivative[1][q1][t] + 
2 c2 (Derivative[1][q1][t] - Derivative[1][q2][t]) + 
l1 (g m2 Sin[q1[t]] + g m3 Sin[q1[t]] + 
   l2 m3 Sin[q1[t] - q2[t]] Derivative[1][q2][t]^2 + 
   l1 (m2 + m3) Derivative[2][q1][t] + 
   l2 m3 Cos[q1[t] - q2[t]] Derivative[2][q2][t]) == 
l1 f[t] Sin[q1[t] - q2[t]], 
2 k2 q2[t] + 2 c2 (-Derivative[1][q1][t] + Derivative[1][q2][t]) + 
l2 m3 (g Sin[q2[t]] - 
   l1 Sin[q1[t] - q2[t]] Derivative[1][q1][t]^2 + 
   l1 Cos[q1[t] - q2[t]] Derivative[2][q1][t] + 
   l2 Derivative[2][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]

enter image description here

$\endgroup$
2
  • $\begingroup$ 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 $\endgroup$
    – Petrini
    Oct 17, 2019 at 14:50
  • 1
    $\begingroup$ Should take only a couple of seconds :) Just delete 'Nonlinear' in NonlinearStateSpaceModel or wrap the result above in StateSpaceModel. $\endgroup$ Oct 17, 2019 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.