26 #if defined (HAVE_CONFIG_H)
43 template <
typename Matrix>
49 const element_type zero = element_type ();
51 bool singular =
false;
74 element_type *colj = Tp +
n*j;
76 colj[j] = sqrt (colj[j]);
82 const element_type *coli = Tp +
n*i;
84 colj[i] /= (coli[i] + colj[j]);
85 const element_type colji = colj[i];
87 colj[k] -= coli[k] * colji;
93 "sqrtm: matrix is singular, may not have a square root");
96 template <
typename Matrix,
typename ComplexMatrix,
typename ComplexSCHUR>
109 real_type cutoff = 0;
111 real_type
eps = std::numeric_limits<real_type>::epsilon ();
124 if (!
x.diag ().any_element_is_negative ())
136 if (!
x.diag ().any_element_is_negative ())
140 retval =
x.transpose ();
153 cutoff = 10 *
x.rows () *
eps *
xnorm (
x, one);
175 retval =
x.transpose ();
185 ComplexSCHUR schur_fact (
x,
"",
true);
186 x = schur_fact.schur_matrix ();
187 u = schur_fact.unitary_schur_matrix ();
196 if (cutoff > 0 &&
xnorm (
imag (res), one) <= cutoff)
208 DEFUN (sqrtm, args, nargout,
220 if (args.length () != 1)
228 if (
n != nc || arg.
ndims () > 2)
242 retval(0) = arg.
sqrt ();
245 math::schur<FloatComplexMatrix>> (arg);
248 math::schur<ComplexMatrix>> (arg);
ComplexMatrix xgemm(const ComplexMatrix &a, const ComplexMatrix &b, blas_trans_type transa, blas_trans_type transb)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
bool is_unknown(void) const
OCTAVE_API int type(bool quiet=true)
MatrixType matrix_type(void) const
octave_idx_type rows(void) const
bool isnumeric(void) const
bool is_diag_matrix(void) const
octave_idx_type columns(void) const
octave_value sqrt(void) const
bool is_single_type(void) const
bool iscomplex(void) const
ColumnVector real(const ComplexColumnVector &a)
ColumnVector imag(const ComplexColumnVector &a)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning_with_id(const char *id, const char *fmt,...)
void err_square_matrix_required(const char *fcn, const char *name)
F77_RET_T const F77_DBLE * x
class OCTAVE_API ComplexMatrix
class OCTAVE_API FloatComplexMatrix
class OCTAVE_API FloatMatrix
double xfrobnorm(const Matrix &x)
double xnorm(const ColumnVector &x, double p)
ComplexMatrix octave_value_extract< ComplexMatrix >(const octave_value &v)
Matrix octave_value_extract< Matrix >(const octave_value &v)
static octave_value do_sqrtm(const octave_value &arg)
static void sqrtm_utri_inplace(Matrix &T)