Mercurial > matrix-functions
diff mftoolbox/sqrtm_newton_full.m @ 0:8f23314345f4 draft
Create local repository for matrix toolboxes. Step #0 done.
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Wed, 06 May 2015 14:56:53 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mftoolbox/sqrtm_newton_full.m Wed May 06 14:56:53 2015 +0200 @@ -0,0 +1,26 @@ +function [X,k] = sqrtm_newton_full(A, X0) +%SQRTM_NEWTON_FULL Matrix square root by full Newton method. +% [X,K] = SQRTM_NEWTON_FULL(A, X0) applies Newton's method to +% compute a square root X of the matrix A, with starting matrix X0. +% Default: X0 = A. K is the number of iterations. + +if nargin < 2, X0 = A; end + +X = X0; +tol = mft_tolerance(A); +maxit = 50; + +for k = 1:maxit + + Xold = X; + R = A - X^2; + % Solve XE + EX = R. + E = sylvsol(X,X,R); + X = X + E; + + reldiff = norm(X - Xold,inf)/norm(X,inf); + + if reldiff <= tol; return; end + +end +error('Not converged after %2.0f iterations', maxit)