# Jacobian of nonlinear dynamic equations

As a supplementary to my question Calculate state-space model from dynamic equations, I have mixed linear and nonlinear dynamic equations, and want to linearize the nonlinear ones around an opperating given point, and keep the linear differential equations as it is, and finally calculate the state space model. For this, I use the NonlinearStateSpaceModel command first to establish the equations for each state separately and then use JacobianMatrix command to calculate the final linearized state space matrix around an opperating point which is 1 in this case. as a simple example:

JacobianMatrix[1, NonlinearStateSpaceModel[Equal @@@ Flatten[Solve[ Eliminate[{a[t] == b1 + c *x1''[t],
b2 == e *(x2[t] - y[t]) +
f *(x2'[t] - y'[t]) +
d *x2''[t],
g*y''[t] + e*(y[t] - x2[t]) + f*(y'[t] - x2'[t]) + m*L == 0,
n *z''[t] == m - R, a1 == b3 + c1*alfa1''[t],
b4 - d1*L1*sin (alfa2[t]) - n2*x3''[t]*L1*sin (alfa2[t]) ==
r1*alfa2''[t], d1 == M1*x4''[t], b1 == b2, y[t] == z[t]/L,
y'[t] ==
z'[t]/L, y''[t] == z''[t]/L, x2[t] == x1[t],
x2'[t] == x1'[t], x2''[t] == x1''[t], alfa1[t] == alfa2[t],
alfa1'[t] == alfa2'[t], alfa1''[t] == alfa2''[t],
x3[t] == z[t], x3'[t] == z'[t], x3''[t] == z''[t],
x4''[t] ==
x3''[t] + L1*alfa2''[t]*sin (alfa2[t]) +
L1*(alfa2'[t])^2*cos (alfa2[t]), b3 == b4}, {b1, b2, x2[t],
x2'[t], x2''[t], y[t],
y'[t], y''[t], m, x3[t], d1, b3,
b4, x3'[t], x3''[t], alfa2[t], alfa2'[t], alfa2''[t], x4[t],
x4'[t], x4''[t]}], {x1''[t], z''[t], alfa1''[t]}]],
{{x1'[t], 0}, {x1[t], 0}, {z'[t], 0}, {z[t], 0}, {alfa1'[t], 0},
{alfa1[t], 0}}, {{a[t], 0}}, z'[t], t]]


which gives an answer for NonlinearStateSpaceModel but the Jacobian part is not working. Other solutions for this kind of example are welcome. (all commands should be in one line code)

• What is this: "all commands should be in one line of code"? Commented Nov 15, 2016 at 14:43
• I meant I can't split the equations to two parts: linear and nonlinear and then perform on them separately, like linearizing the nonlinear ones and eventually calculating a unique state space model. @bill s
– F R
Commented Nov 15, 2016 at 14:47
• I think StateSpaceModel is the function you are looking for. There are probably issues with the set of equations you are passing onto the first argument of StateSpaceModel. If that is correct, probably you will get the results you are expecting. Commented Nov 15, 2016 at 15:22

I'm afraid this is a duplicate of Calculate state-space model from dynamic equations.

What is "applied point 1"?

StateSpaceModel linearizes by computing the Jacobian matrix around the operating point of 0 (as specified) for all states and inputs. It keeps the linear equations as is and linearizes only the nonlinear ones. (And there is a typo in your input. Sin[...] instead of sin(...)).

StateSpaceModel[Equal @@@
Flatten[Solve[Eliminate[{a[t] == b1 + c*x1''[t],
b2 == e*(x2[t] - y[t]) + f*(x2'[t] - y'[t]) + d*x2''[t],
g*y''[t] + e*(y[t] - x2[t]) + f*(y'[t] - x2'[t]) + m*L == 0,
n*z''[t] == m - R, a1 == b3 + c1*alfa1''[t],
b4 - d1*L1*Sin [alfa2[t]] - n2*x3''[t]*L1*Sin [alfa2[t]] ==
r1*alfa2''[t], d1 == M1*x4''[t], b1 == b2, y[t] == z[t]/L,
y'[t] == z'[t]/L, y''[t] == z''[t]/L, x2[t] == x1[t],
x2'[t] == x1'[t], x2''[t] == x1''[t], alfa1[t] == alfa2[t],
alfa1'[t] == alfa2'[t], alfa1''[t] == alfa2''[t], x3[t] == z[t],
x3'[t] == z'[t], x3''[t] == z''[t],
x4''[t] ==
x3''[t] + L1*alfa2''[t]*sin (alfa2[t]) +
L1*(alfa2'[t])^2*cos (alfa2[t]), b3 == b4}, {b1, b2, x2[t],
x2'[t], x2''[t], y[t], y'[t], y''[t], m, x3[t], d1, b3, b4,
x3'[t], x3''[t], alfa2[t], alfa2'[t], alfa2''[t], x4[t], x4'[t],
x4''[t]}], {x1''[t], z''[t], alfa1''[t]}]], {{x1'[t],
0}, {x1[t], 0}, {z'[t], 0}, {z[t], 0}, {alfa1'[t], 0}, {alfa1[t],
0}}, {{a[t], 0}}, z'[t], t]


• Thanks,it is working, but still in your code, in some parts you used Sin[] but in other parts you used sin() and cos(), is that a typo? @Suba Thomas
– F R
Commented Nov 15, 2016 at 15:24
• Yes it is. I only caught some. sin() and cos() must become Sin[] and Cos[]. Commented Nov 15, 2016 at 15:25
• There are bigger issues than that. That's why I left it as is. Evaluate the first argument that is being passed to StateSpaceModel. There are no $alfa1[t]$ terms, yet you pass this variable and it's derivative in the second argument. That makes no sense. StateSpaceModel, however, faithfully does what you asked it and the final row in the three top matrices turn out as zero. Weird, but that is what you gave as input. Commented Nov 15, 2016 at 18:27
• yes true, there is no complete answer. it complains that there are inverse functions being used! but I do not really get the problem. is it because of ArcSin[] and ArcCos[] functions that it cannot give the correct result? thanks in advance, @Suba Thomas
– F R
Commented Nov 17, 2016 at 16:52
• The problem is in the first argument. I do not know whether it is because the model was formulated incorrectly, or the input-output structure, or something else. From the variables you are using, I'm guessing it's a mechanical or electromechanical system. These systems should not typically have the issues you are encountering. Commented Nov 17, 2016 at 17:46