In[]:=
CompoundExpression[
]
​​deploy
Sat 18 Nov 2023 15:15:48
Parent notebook: https://www.wolframcloud.com/obj/yaroslavvb/newton/lyapunov.nb
Forum q: https://math.stackexchange.com/questions/4808422/least-squares-solution-to-underdetermined-lyapunov-equation
​

Init


Main

In[]:=
d=3;​​SeedRandom[1];​​ii=IdentityMatrix[d];​​{A,B}=RandomInteger[{-2,2},{2,d,d}];​​A=makePosdef[A];​​B=makePosdef[B];​​Print["A=",A//MatrixForm];​​Print["B=",B//MatrixForm];​​​​sol1=lyapLeastSquares[A,B];​​sol2=lyapSpectral[A,B];​​​​Print["solution least squares: ",sol1//MatrixForm];​​Print["solution lyapunov: ",sol2//Simplify//MatrixForm];​​
A=
8
-8
-8
-8
9
8
-8
8
8
B=
5
5
-5
5
9
-3
-5
-3
6
errorLsqr=
1
4
errorSpectral=0.25
solution least squares:
1789
640
183
40
-
1329
640
183
40
73
10
-
123
40
-
1329
640
-
123
40
869
640
solution lyapunov:
1789
640
183
40
-
1329
640
183
40
73
10
-
123
40
-
1329
640
-
123
40
869
640