42 template <
class Matrix>
48 const element_type zero = element_type ();
50 bool singular =
false;
71 element_type *colj = Tp + n*j;
73 colj[j] =
sqrt (colj[j]);
79 const element_type *coli = Tp + n*i;
80 const element_type colji = colj[i] /= (coli[i] + colj[j]);
82 colj[k] -= coli[k] * colji;
88 "sqrtm: matrix is singular, may not have a square root");
91 template <
class Matrix,
class ComplexMatrix,
class ComplexSCHUR>
104 real_type cutoff = 0, one = 1;
105 real_type
eps = std::numeric_limits<real_type>::epsilon ();
147 cutoff = 10 * x.
rows () * eps *
xnorm (x, one);
190 if (cutoff > 0 &&
xnorm (
imag (res), one) <= cutoff)
202 DEFUN (sqrtm, args, nargout,
204 @deftypefn {Built-in Function} {@var{s} =} sqrtm (@var{A})\n\
205 @deftypefnx {Built-in Function} {[@var{s}, @var{error_estimate}] =} sqrtm (@var{A})\n\
206 Compute the matrix square root of the square matrix @var{A}.\n\
208 Ref: N.J. Higham. @cite{A New sqrtm for @sc{matlab}}. Numerical\n\
209 Analysis Report No. 336, Manchester @nospell{Centre} for Computational\n\
210 Mathematics, Manchester, England, January 1999.\n\
211 @seealso{expm, logm}\n\
216 int nargin = args.
length ();
229 if (n != nc || arg.
ndims () > 2)
243 retval(0) = arg.
sqrt ();
245 retval(0) = do_sqrtm<FloatMatrix, FloatComplexMatrix, FloatComplexSCHUR>
248 retval(0) = do_sqrtm<Matrix, ComplexMatrix, ComplexSCHUR> (
arg);