# To find Stability of Non Linear System using Lyapnov Stabilitiy Technique – Basic Example

Various types of Stability are there for solution of differential equation of the dynamic systems. One the major stability technique for non linear dynamic system is called lyapunov.
A detailed post on the Lyapunov Stability Criteria will be uploaded soon.

Following posts gives a very basic example to hel user use the lyapunov function in Matlab.

# Problem

A non linear system with state space equation of
$\large \dot{x_{1}} = -x_{1} + 2x_{1}x_{2}$
$\large \dot{x_{2}} = -x_{2}$
Find Stability at equilibrium points

# Solution

Given system as
$\large \dot{x_{1}} = -x_{1} + 2x_{1}x_{2}$
$\large \dot{x_{2}} = -x_{2}$
Calculating the equilibrium points
$\large \dot{x_{2}} = -x_{2} = 0$
$\large x_{2} = 0$
$\large \dot{x_{1}} = -x_{1} + 2x_{1}x_{2} = 0$
Substitute $x_{2} = 0$ in above equation
we get $x_{1} = 0$
Therefore the equilibrium points are at x = (0,0)
$\large A = [\begin{pmatrix}
\frac{\partial f_{1}}{\partial x_{1}} & \frac{\partial f_{1}}{\partial x_{2}}\\
\frac{\partial f_{2}}{\partial x_{1}} & \frac{\partial f_{2}}{\partial x_{2}}
\end{pmatrix}] \newline at\; x=(0,0)$

$\large A = [\begin{pmatrix}
-1 & 0 \\
0 & -1
\end{pmatrix}]
$

$\large Q = [\begin{pmatrix}
1 & 0 \\
0 & 1
\end{pmatrix}]
$

Q is the identity matrix with order of A and is a positive definitive matrix.
Now using the MAtrix A and Matrix Q above we will write a Matlab Program

# Matlab Code

%--------------------------------------------------------------------------
%
% From the question above we will be solving for stability
% x1' = -x1 + 2x1x2
% x2' = -x2
% equiliibrium at x1 = 0 and x2 = 0
%
% Given -------------------------------------------------------------------
MatrixA = [-1 0;0 -1];
MatrixQ = [1 0;0 1];
% Lyap(A,Q) ---------------------------------------------------------------
% AX + XA' + Q = 0
% A = MatrixA, Q = MatrixQ, X = MatrixX
% -------------------------------------------------------------------------
MatrixX = lyap(MatrixA,MatrixQ);
disp('Lyapunov Solution is MatrixX = ');
disp(MatrixX);
k = eig(MatrixX);
disp('Eigen values of Lyapunov: ');
disp(k);
if(k(1)>0 && k(2)>0)
disp('The System is Positive Definite and hence stable');
else
disp('The System is not Positive Definite and hence unstable');
end


# Output:

Here the System is stable and has a unique solution to the said equation.

Lyapunov Solution is MatrixX =
0.5000 0
0 0.5000
Eigen values of Lyapunov:
0.5000
0.5000
The System is Positive Definite and hence stable


# Another Problem with Unstability

Given Non-Linear System
$\large \dot{x_{1}} = x_{2}$
$\large \dot{x_{2}} = x_{2} - x_{1}^{3}$
Calculating the equilibrium points
$\large \dot{x_{2}} = x_{2} = 0$
$\large x_{2} = 0$
$\large \dot{x_{1}} = x_{2} - x_{1]^{3} = 0$
Substitute $x_{2} = 0$ in the above equation
We will get $x_{1} = 0$

Therefore the equilibrium points are at x=(0,0)
$\large A = [\begin{pmatrix}
\frac{\partial f_{1}}{\partial x_{1}} & \frac{\partial f_{1}}{\partial x_{2}}\\
\frac{\partial f_{2}}{\partial x_{1}} & \frac{\partial f_{2}}{\partial x_{2}}
\end{pmatrix}] \newline at\; x=(0,0)$

$\large A = [\begin{pmatrix}
-1 & 0 \\
0 & -1
\end{pmatrix}]
$

$\large Q = [\begin{pmatrix}
1 & 0 \\
0 & 1
\end{pmatrix}]
$

Q is the identity matrix with order of A and is a positive definitive matrix.
Now using the Matrix A and Matrix Q above we will write a Matlab Program

# Matlab Program

To show the non uniqueness of the non linear system we are going to use the Matrix A and Matrix Q given above theory for the non linear system and see that the unique solution does not exists.

%--------------------------------------------------------------------------
%
% From the question above we will be solving for stability
% x1' = -x1 + 2x1x2
% x2' = -x2
% equiliibrium at x1 = 0 and x2 = 0
%
% Given -------------------------------------------------------------------
MatrixA = [0 1;0 -1];
MatrixQ = [1 0;0 1];
% Lyap(A,Q) ---------------------------------------------------------------
% AX + XA' + Q = 0
% A = MatrixA, Q = MatrixQ, X = MatrixX
% -------------------------------------------------------------------------
MatrixX = lyap(MatrixA,MatrixQ);
disp('Lyapunov Solution is MatrixX = ');
disp(MatrixX);
k = eig(MatrixX);
disp('Eigen values of Lyapunov: ');
disp(k);
if(k(1)>0 && k(2)>0)
disp('The System is Positive Definite and hence stable');
else
disp('The System is not Positive Definite and hence unstable');
end


# Output:

Here as we already know that the system is unstable therefore the unique solution does not exists. We will get the output as shown.

??? Error using ==> lyap at 70
The solution of this Lyapunov equation does not exist or is not unique.
Error in ==> stability_analysis at 51
MatrixX = lyap(MatrixA,MatrixQ);


To be Updated