Lets take A1 and A2 both as Identity matrices of order 5. Then P=eye(5) shall be the exact value of P which satisfies A2=P*A1*inv(P). How do we obtain this P by solving this equation in matlab code?
5x5 matrix (P) with all 25 values unknown. I have two known matrices of size 5x5 each (A1 and A2) and the relation P*A1*inv(P)=A2. How do I obtain P?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Richa Dubey
am 22 Jan. 2022
Kommentiert: Richa Dubey
am 23 Jan. 2022
A2=[1.1581 0.0279 -0.0739 -0.0169 -0.0100
-0.9172 0.7637 0.5688 0.1299 0.0795
12.8599 2.5037 -5.4500 -1.4719 -0.8824
-39.7814 -7.8095 20.0738 5.5809 2.7482
-27.9052 -5.5369 14.1918 3.2387 2.9446];
A1=[ -1.0093 0.0645 -0.0795 -0.0172 -0.5886
4.1505 0.0040 -0.6850 -0.0824 -2.9194
1.1250 0.7191 -2.4753 -0.0098 -0.3402
-1.1250 1.1521 -0.2040 -1.2556 -0.4159
2.5296 0.0455 -0.1234 -0.0646 -3.7925];
syms P a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 d3 e3 a4 b4 c4 d4 e4 a5 b5 c5 d5 e5
P1=[a1 b1 c1 d1 e1
a2 b2 c2 d2 e2
a3 b3 c3 d3 e3
a4 b4 c4 d4 e4
a5 b5 c5 d5 e5];
V=vpa(P1*A1*inv(P1),6);
solve(V==A2)
%%This gives all 0s.
%%I also tried the below code but still getting zeroes.
global A1 A2 B1 B2
guess=[10;0.1; 0.1; 0.1; 0.1; 0.1; 10; 0.1; 0.1; 0.1; 0.1; 0.1; 10; 0.1; 0.1; 0.1; 0.1; 0.1; 1; 0.1; 0.1; 0.1; 0.1; 0.1; 1];
%guess=[1 -1 -2 1 2 1 1 -3 2 4 -2 1 1 3 2 3 -3 1 1.5 2.5 2.8 3 3.5 3.2 1];
%guess=[1 0.1 0.1 0.1 0.1 0.1 1 0.1 0.1 0.1 0.1 0.1 1 0.1 0.1 0.1 0.1 0.1 1 0.1 0.1 0.1 0.1 0.1 1];
options = optimoptions(@lsqnonlin,'OptimalityTolerance', 1e-16, 'FunctionTolerance', 1e-16,'StepTolerance',1e-16);
result=lsqnonlin(@eqns,guess,[],[],options);
%result=fsolve(@eqns,guess,options);
P=[result(1) result(6) result(11) result(16) result(21)
result(2) result(7) result(12) result(17) result(22)
result(3) result(8) result(13) result(18) result(23)
result(4) result(9) result(14) result(19) result(24)
result(5) result(10) result(15) result(20) result(25)];
function fncs = eqns(z)
global A1 A2 B1 B2
a1=z(1);
a2=z(2);
a3=z(3);
a4=z(4);
a5=z(5);
b1=z(6);
b2=z(7);
b3=z(8);
b4=z(9);
b5=z(10);
c1=z(11);
c2=z(12);
c3=z(13);
c4=z(14);
c5=z(15);
d1=z(16);
d2=z(17);
d3=z(18);
d4=z(19);
d5=z(20);
e1=z(21);
e2=z(22);
e3=z(23);
e4=z(24);
e5=z(25);
P1=[a1 b1 c1 d1 e1
a2 b2 c2 d2 e2
a3 b3 c3 d3 e3
a4 b4 c4 d4 e4
a5 b5 c5 d5 e5];
expres=P1*A1*inv(P1)-A2;
fncs(1)= expres(1,1);
fncs(2)= expres(1,2);
fncs(3)= expres(1,3);
fncs(4)= expres(1,4);
fncs(5)= expres(1,5);
fncs(6)= expres(2,1);
fncs(7)= expres(2,2);
fncs(8)= expres(2,3);
fncs(9)= expres(2,4);
fncs(10)= expres(2,5);
fncs(11)= expres(3,1);
fncs(12)= expres(3,2);
fncs(13)= expres(3,3);
fncs(14)= expres(3,4);
fncs(15)= expres(3,5);
fncs(16)= expres(4,1);
fncs(17)= expres(4,2);
fncs(18)= expres(4,3);
fncs(19)= expres(4,4);
fncs(20)= expres(4,5);
fncs(21)= expres(5,1);
fncs(22)= expres(5,2);
fncs(23)= expres(5,3);
fncs(24)= expres(5,4);
fncs(25)= expres(5,5);
fncs(26)= expres(4,5);
end
Even if we assume that A1 and A2 do not satisfy this relation A2=P*A1*inv(P), how do we find P for some other A1 A2 which do satisfy this relation. Please help!
2 Kommentare
Matt J
am 22 Jan. 2022
Then P=eye(5) shall be the exact value of P which satisfies A2=P*A1*inv(P).
That will be one solution, but clearly there will be infinitely many alternative solutions as well. Any invertible P would solve the equation.
Akzeptierte Antwort
Matt J
am 22 Jan. 2022
Bearbeitet: Matt J
am 22 Jan. 2022
A necessary but not sufficient condition for a solution is A2*P-P*A1=0, which is equivalent to K*P(:)=0 where K=kron(I,A2)-kron(A1.',I). The necessary condition can therefore be solved (if a solution exists) with null(). Example:
A1=[1.1581 0.0279 -0.0739 -0.0169 -0.0100
-0.9172 0.7637 0.5688 0.1299 0.0795
12.8599 2.5037 -5.4500 -1.4719 -0.8824
-39.7814 -7.8095 20.0738 5.5809 2.7482
-27.9052 -5.5369 14.1918 3.2387 2.9446];
P0=rand(5);
A2=P0*A1/P0;
d=length(A1);
I=eye(d);
K=kron(I,A2)-kron(A1.',I);
P=reshape(null(K),d,d,[]);
errors=nan(size(P,3),1);
for j=1:numel(errors)
Pj=P(:,:,j);
errors(j)=max(abs(A2-Pj*A1/Pj),[],'all');
end
P=P(:,:,errors<1e-8)
This does produce several solutions, though it is not clear to me if solving the necessary conditions will always find one.
4 Kommentare
Matt J
am 22 Jan. 2022
Bearbeitet: Matt J
am 22 Jan. 2022
This method isnt working when null(K) in the above code returns an empty matrix.
If null(K) is empty, then the method has succeeded. It has successfully determined that no solutions exists. For a solution to exist, it must lie in the nullspace of K and therefore null(K) cannot be empty.
Could you please suggest a soln which is 'necessary and sufficient' for satisfying A2=P*A1*inv(P)?
See my comment above about fminunc.
Weitere Antworten (1)
Torsten
am 22 Jan. 2022
Bearbeitet: Torsten
am 22 Jan. 2022
I think you could also get such P by solving the linear optimization problem
min: sum_ij (eij+ + eij-)
under the constraints
E+ - E- = (P+ - P-)*A1 - A2*(P+ - P-)
sum_ij (pij+ + pij-) = 1
E+,E-,P+,P- >= 0
The matrix P = P+ - P- should have the property P*A1 = A2*P if the optimal value of the objective is 0.
Otherwise, such P does not exist.
Note that it's not guaranteed that P is invertible (I guess). But it's different from the trivial solution P=0.
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!