Mercurial > matrix-functions
comparison toolbox/poldec.m @ 2:c124219d7bfa draft
Re-add the 1995 toolbox after noticing the statement in the ~higham/mctoolbox/ webpage.
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Thu, 07 May 2015 18:36:24 +0200 |
parents | 8f23314345f4 |
children |
comparison
equal
deleted
inserted
replaced
1:e471a92d17be | 2:c124219d7bfa |
---|---|
1 function [U, H] = poldec(A) | |
2 %POLDEC Polar decomposition. | |
3 % [U, H] = POLDEC(A) computes a matrix U of the same dimension | |
4 % (m-by-n) as A, and a Hermitian positive semi-definite matrix H, | |
5 % such that A = U*H. | |
6 % U has orthonormal columns if m >= n, and orthonormal rows if m <= n. | |
7 % U and H are computed via an SVD of A. | |
8 % U is a nearest unitary matrix to A in both the 2-norm and the | |
9 % Frobenius norm. | |
10 | |
11 % Reference: | |
12 % N.J. Higham, Computing the polar decomposition---with applications, | |
13 % SIAM J. Sci. Stat. Comput., 7(4):1160--1174, 1986. | |
14 % | |
15 % (The name `polar' is reserved for a graphics routine.) | |
16 | |
17 [m, n] = size(A); | |
18 | |
19 [P, S, Q] = svd(A, 0); % Economy size. | |
20 if m < n % Ditto for the m<n case. | |
21 S = S(:, 1:m); | |
22 Q = Q(:, 1:m); | |
23 end | |
24 U = P*Q'; | |
25 if nargout == 2 | |
26 H = Q*S*Q'; | |
27 H = (H + H')/2; % Force Hermitian by taking nearest Hermitian matrix. | |
28 end |