I have a 4x4 matrix given and I have to solve this lyapnov equation and find the unknown matrix which satisfies the below equation .
a = [0 1 0 0;0 0 -1 0;0 0 0 1;0 0 5 0];
f = [-1 1 0 0;-1 -1 0 0;0 0 -1.5 0.5;0 0 -0.5 -1.5];
b = [0;1;0;-2];
k = [1 0 1 0];
The equation is given at - tf = bk.
a*t - t*f = b*k ;
where t = 4x4 unknown matrix . Can you help me find matrix t ?
CodePudding user response:
You could also use symbolic math to create a system of linear equation and then solve this system:
% Your variables
a = [0 1 0 0;0 0 -1 0;0 0 0 1;0 0 5 0];
f = [-1 1 0 0;-1 -1 0 0;0 0 -1.5 0.5;0 0 -0.5 -1.5];
b = [0;1;0;-2];
k = [1 0 1 0];
% The unknows:
t = sym('t', [4 4]);
% Create the symbolic system of linear equation
eq = a*t - t*f == b*k;
% Equation to matrix
[A,b] = equationsToMatrix(eq);
% Solve the system and get a numeric solution
sol = double(reshape(A\b,[4,4])).'
% sol =
%
% 0.0690 -0.3276 -0.0853 -0.1973
% 0.2586 0.3966 0.2267 0.2533
% -0.3448 0.1379 -0.5333 0.2667
% 0.2069 -0.4828 0.6667 -0.6667
CodePudding user response:
You should be aware that matrix f
is invertable, we can use dlyap
like below
t = dlyap(a,inv(f),-b*k/f)
or a simpler one
t = lyap(a,-f,-b*k)
which gives
t =
0.0690 -0.3276 -0.0853 -0.1973
0.2586 0.3966 0.2267 0.2533
-0.3448 0.1379 -0.5333 0.2667
0.2069 -0.4828 0.6667 -0.6667
To verify this
>> a*t-t*f-b*k
ans =
1.0e-15 *
0 0 0.0555 0
0 0 0 -0.0555
0.0833 0 0.1110 0
0 0.1110 0 0