linearize a second-order system without symbolic math toolbox or linearize command in matlab

To linearize a second-order system in MATLAB without using the Symbolic Math Toolbox or the lineraize command, you can follow these steps:

  1. Define the second-order system in terms of differential equations.
  2. Convert the differential equations to Laplace domain equations using the Laplace transform.
  3. Approximate the nonlinear terms in the Laplace domain equations using a Taylor series expansion.
  4. Substitute the approximated equations back into the Laplace domain equations.
  5. Find the transfer function of the system in terms of the Laplace variable.
  6. Use the tf2ss command to convert the transfer function to state-space representation.

Here's an example code snippet that demonstrates one way to linearize a second-order system using these steps:

main.m
% Define parameters of the nonlinear system
m = 1;      % mass
k = 10;     % spring constant
b = 2;      % damping coefficient

% Define the differential equations
syms x(t) v(t)
eq1 = diff(x, t, 2) == -(k/m)*x - (b/m)*v;
eq2 = diff(v, t, 2) == -(k/m)*v - (b/m)*diff(x, t);

% Convert the differential equations to Laplace domain equations
X = laplace(x);
V = laplace(v);
EQ1 = subs(eq1, [x(t) diff(x(t), t) v(t) diff(v(t), t)], [X s*X V s*V]);
EQ2 = subs(eq2, [x(t) diff(x(t), t) v(t) diff(v(t), t)], [X s*X V s*V]);

% Approximate nonlinear terms using Taylor series expansion
EQ1 = taylor(EQ1, [X V], 'Order', 2);
EQ2 = taylor(EQ2, [X V], 'Order', 2);

% Substitute approximated equations back into Laplace domain equations
EQ1 = subs(EQ1, [X V diff(X, t) diff(V, t)], [x v s*x s*v]);
EQ2 = subs(EQ2, [X V diff(X, t) diff(V, t)], [x v s*x s*v]);
EQ1 = simplify(EQ1);
EQ2 = simplify(EQ2);

% Find the transfer function of the system in terms of the Laplace variable
H = solve(EQ1, V/s^2);

% Convert transfer function to state-space representation
[A,B,C,D] = tf2ss(double(coeffs(H, 'All')));
1095 chars
32 lines

Note that this is just one way to linearize a second-order system, and the exact approach may vary depending on the specific system being analyzed. Additionally, the resulting linearized system will only be valid for small perturbations around the equilibrium point.

gistlibby LogSnag