GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
|
#include "CmplxQR.h"
#include "CmplxQRP.h"
#include "dbleQR.h"
#include "dbleQRP.h"
#include "fCmplxQR.h"
#include "fCmplxQRP.h"
#include "floatQR.h"
#include "floatQRP.h"
#include "SparseQR.h"
#include "SparseCmplxQR.h"
#include "defun-dld.h"
#include "error.h"
#include "gripes.h"
#include "oct-obj.h"
#include "utils.h"
Go to the source code of this file.
Functions | |
static bool | check_index (const octave_value &i, bool vector_allowed=false) |
static bool | check_qr_dims (const octave_value &q, const octave_value &r, bool allow_ecf=false) |
DEFUN_DLD (qr, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{Q}, @var{R}, @var{P}] =} qr (@var{A})\n\ @deftypefnx {Loadable Function} {[@var{Q}, @var{R}, @var{P}] =} qr (@var{A}, '0')\n\ @deftypefnx {Loadable Function} {[@var{C}, @var{R}] =} qr (@var{A}, @var{B})\n\ @deftypefnx {Loadable Function} {[@var{C}, @var{R}] =} qr (@var{A}, @var{B}, '0')\n\ @cindex QR factorization\n\ Compute the QR@tie{}factorization of @var{A}, using standard @sc{lapack}\n\ subroutines. For example, given the matrix @code{@var{A} = [1, 2; 3, 4]},\n\ \n\ @example\n\ [@var{Q}, @var{R}] = qr (@var{A})\n\ @end example\n\ \n\ @noindent\n\ returns\n\ \n\ @example\n\ @group\n\ @var{Q} =\n\ \n\ -0.31623 -0.94868\n\ -0.94868 0.31623\n\ \n\ @var{R} =\n\ \n\ -3.16228 -4.42719\n\ 0.00000 -0.63246\n\ @end group\n\ @end example\n\ \n\ The @code{qr} factorization has applications in the solution of least\n\ squares problems\n\ @tex\n\ $$\n\ \\min_x \\left\\Vert A x - b \\right\\Vert_2\n\ $$\n\ @end tex\n\ @ifnottex\n\ \n\ @example\n\ min norm(A x - b)\n\ @end example\n\ \n\ @end ifnottex\n\ for overdetermined systems of equations (i.e.,\n\ @tex\n\ $A$\n\ @end tex\n\ @ifnottex\n\ @var{A}\n\ @end ifnottex\n\ is a tall, thin matrix). The QR@tie{}factorization is\n\ @tex\n\ $QR = A$ where $Q$ is an orthogonal matrix and $R$ is upper triangular.\n\ @end tex\n\ @ifnottex\n\ @code{@var{Q} * @var{Q} = @var{A}} where @var{Q} is an orthogonal matrix and\n\ @var{R} is upper triangular.\n\ @end ifnottex\n\ \n\ If given a second argument of @qcode{'0'}, @code{qr} returns an economy-sized\n\ QR@tie{}factorization, omitting zero rows of @var{R} and the corresponding\n\ columns of @var{Q}.\n\ \n\ If the matrix @var{A} is full, the permuted QR@tie{}factorization\n\ @code{[@var{Q}, @var{R}, @var{P}] = qr (@var{A})} forms the\n\ QR@tie{}factorization such that the diagonal entries of @var{R} are\n\ decreasing in magnitude order. For example, given the matrix @code{a = [1,\n\ 2; 3, 4]},\n\ \n\ @example\n\ [@var{Q}, @var{R}, @var{P}] = qr (@var{A})\n\ @end example\n\ \n\ @noindent\n\ returns\n\ \n\ @example\n\ @group\n\ @var{Q} =\n\ \n\ -0.44721 -0.89443\n\ -0.89443 0.44721\n\ \n\ @var{R} =\n\ \n\ -4.47214 -3.13050\n\ 0.00000 0.44721\n\ \n\ @var{P} =\n\ \n\ 0 1\n\ 1 0\n\ @end group\n\ @end example\n\ \n\ The permuted @code{qr} factorization @code{[@var{Q}, @var{R}, @var{P}] = qr\n\ (@var{A})} factorization allows the construction of an orthogonal basis of\n\ @code{span (A)}.\n\ \n\ If the matrix @var{A} is sparse, then compute the sparse\n\ QR@tie{}factorization of @var{A}, using @sc{CSparse}. As the matrix @var{Q}\n\ is in general a full matrix, this function returns the @var{Q}-less\n\ factorization @var{R} of @var{A}, such that @code{@var{R} = chol (@var{A}' *\n\ @var{A})}.\n\ \n\ If the final argument is the scalar @code{0} and the number of rows is\n\ larger than the number of columns, then an economy factorization is\n\ returned. That is @var{R} will have only @code{size (@var{A},1)} rows.\n\ \n\ If an additional matrix @var{B} is supplied, then @code{qr} returns\n\ @var{C}, where @code{@var{C} = @var{Q}' * @var{B}}. This allows the\n\ least squares approximation of @code{@var{A} \\ @var{B}} to be calculated\n\ as\n\ \n\ @example\n\ @group\n\ [@var{C}, @var{R}] = qr (@var{A}, @var{B})\n\ x = @var{R} \\ @var{C}\n\ @end group\n\ @end example\n\ @seealso{chol, hess, lu, qz, schur, svd, qrupdate, qrinsert, qrdelete, qrshift}\n\ @end deftypefn") | |
DEFUN_DLD (qrupdate, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{Q1}, @var{R1}] =} qrupdate (@var{Q}, @var{R}, @var{u}, @var{v})\n\ Given a QR@tie{}factorization of a real or complex matrix\n\ @w{@var{A} = @var{Q}*@var{R}}, @var{Q}@tie{}unitary and\n\ @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization\n\ of @w{@var{A} + @var{u}*@var{v}'}, where @var{u} and @var{v} are\n\ column vectors (rank-1 update) or matrices with equal number of columns\n\ (rank-k update). Notice that the latter case is done as a sequence of rank-1\n\ updates; thus, for k large enough, it will be both faster and more accurate\n\ to recompute the factorization from scratch.\n\ \n\ The QR@tie{}factorization supplied may be either full\n\ (Q is square) or economized (R is square).\n\ \n\ @seealso{qr, qrinsert, qrdelete, qrshift}\n\ @end deftypefn") | |
DEFUN_DLD (qrinsert, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{Q1}, @var{R1}] =} qrinsert (@var{Q}, @var{R}, @var{j}, @var{x}, @var{orient})\n\ Given a QR@tie{}factorization of a real or complex matrix\n\ @w{@var{A} = @var{Q}*@var{R}}, @var{Q}@tie{}unitary and\n\ @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization of\n\ @w{[A(:,1:j-1) x A(:,j:n)]}, where @var{u} is a column vector to be\n\ inserted into @var{A} (if @var{orient} is @qcode{\"col\"}), or the\n\ QR@tie{}factorization of @w{[A(1:j-1,:);x;A(:,j:n)]}, where @var{x}\n\ is a row vector to be inserted into @var{A} (if @var{orient} is\n\ @qcode{\"row\"}).\n\ \n\ The default value of @var{orient} is @qcode{\"col\"}.\n\ If @var{orient} is @qcode{\"col\"},\n\ @var{u} may be a matrix and @var{j} an index vector\n\ resulting in the QR@tie{}factorization of a matrix @var{B} such that\n\ @w{B(:,@var{j})} gives @var{u} and @w{B(:,@var{j}) = []} gives @var{A}.\n\ Notice that the latter case is done as a sequence of k insertions;\n\ thus, for k large enough, it will be both faster and more accurate to\n\ recompute the factorization from scratch.\n\ \n\ If @var{orient} is @qcode{\"col\"},\n\ the QR@tie{}factorization supplied may be either full\n\ (Q is square) or economized (R is square).\n\ \n\ If @var{orient} is @qcode{\"row\"}, full factorization is needed.\n\ @seealso{qr, qrupdate, qrdelete, qrshift}\n\ @end deftypefn") | |
DEFUN_DLD (qrdelete, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{Q1}, @var{R1}] =} qrdelete (@var{Q}, @var{R}, @var{j}, @var{orient})\n\ Given a QR@tie{}factorization of a real or complex matrix\n\ @w{@var{A} = @var{Q}*@var{R}}, @var{Q}@tie{}unitary and\n\ @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization of\n\ @w{[A(:,1:j-1) A(:,j+1:n)]}, i.e., @var{A} with one column deleted\n\ (if @var{orient} is @qcode{\"col\"}), or the QR@tie{}factorization of\n\ @w{[A(1:j-1,:);A(j+1:n,:)]}, i.e., @var{A} with one row deleted (if\n\ @var{orient} is @qcode{\"row\"}).\n\ \n\ The default value of @var{orient} is @qcode{\"col\"}.\n\ \n\ If @var{orient} is @qcode{\"col\"},\n\ @var{j} may be an index vector\n\ resulting in the QR@tie{}factorization of a matrix @var{B} such that\n\ @w{A(:,@var{j}) = []} gives @var{B}.\n\ Notice that the latter case is done as a sequence of k deletions;\n\ thus, for k large enough, it will be both faster and more accurate to\n\ recompute the factorization from scratch.\n\ \n\ If @var{orient} is @qcode{\"col\"},\n\ the QR@tie{}factorization supplied may be either full\n\ (Q is square) or economized (R is square).\n\ \n\ If @var{orient} is @qcode{\"row\"}, full factorization is needed.\n\ @seealso{qr, qrupdate, qrinsert, qrshift}\n\ @end deftypefn") | |
DEFUN_DLD (qrshift, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {[@var{Q1}, @var{R1}] =} qrshift (@var{Q}, @var{R}, @var{i}, @var{j})\n\ Given a QR@tie{}factorization of a real or complex matrix\n\ @w{@var{A} = @var{Q}*@var{R}}, @var{Q}@tie{}unitary and\n\ @var{R}@tie{}upper trapezoidal, return the QR@tie{}factorization\n\ of @w{@var{A}(:,p)}, where @w{p} is the permutation @*\n\ @code{p = [1:i-1, shift(i:j, 1), j+1:n]} if @w{@var{i} < @var{j}} @*\n\ or @*\n\ @code{p = [1:j-1, shift(j:i,-1), i+1:n]} if @w{@var{j} < @var{i}}. @*\n\ \n\ @seealso{qr, qrupdate, qrinsert, qrdelete}\n\ @end deftypefn") | |
template<class MT > | |
static octave_value | get_qr_r (const base_qr< MT > &fact) |
|
static |
Definition at line 753 of file qr.cc.
References octave_value::is_integer_type(), octave_value::is_real_type(), and octave_value::is_scalar_type().
Referenced by DEFUN_DLD().
|
static |
Definition at line 744 of file qr.cc.
References octave_value::columns(), octave_value::ndims(), and octave_value::rows().
Referenced by DEFUN_DLD().
DEFUN_DLD | ( | qr | , |
args | , | ||
nargout | |||
) |
Definition at line 75 of file qr.cc.
References arg(), octave_value::columns(), octave_value::complex_matrix_value(), QR::economy, empty_arg(), error(), error_state, octave_value::float_complex_matrix_value(), octave_value::float_matrix_value(), get_qr_r(), gripe_wrong_type_arg(), octave_value::is_complex_type(), octave_value::is_real_type(), octave_value::is_single_type(), octave_value::is_sparse_type(), octave_value_list::length(), octave_value::matrix_value(), ComplexQRP::P(), FloatComplexQRP::P(), FloatQRP::P(), QRP::P(), print_usage(), ComplexQRP::Pvec(), FloatComplexQRP::Pvec(), QRP::Pvec(), FloatQRP::Pvec(), base_qr< qr_type >::Q(), base_qr< qr_type >::R(), QR::raw, octave_value::rows(), octave_value::sparse_complex_matrix_value(), octave_value::sparse_matrix_value(), QR::std, and warning().
DEFUN_DLD | ( | qrupdate | , |
args | |||
) |
Definition at line 759 of file qr.cc.
References check_qr_dims(), octave_value::complex_matrix_value(), error(), octave_value::float_complex_matrix_value(), octave_value::float_matrix_value(), get_qr_r(), octave_value::is_numeric_type(), octave_value::is_real_type(), octave_value::is_single_type(), octave_value::matrix_value(), print_usage(), base_qr< qr_type >::Q(), Q, FloatQR::update(), ComplexQR::update(), FloatComplexQR::update(), and QR::update().
DEFUN_DLD | ( | qrinsert | , |
args | |||
) |
Definition at line 939 of file qr.cc.
References check_index(), check_qr_dims(), octave_value::complex_matrix_value(), error(), octave_value::float_complex_matrix_value(), octave_value::float_matrix_value(), get_qr_r(), FloatQR::insert_col(), ComplexQR::insert_col(), FloatComplexQR::insert_col(), QR::insert_col(), FloatQR::insert_row(), ComplexQR::insert_row(), FloatComplexQR::insert_row(), QR::insert_row(), octave_value::is_numeric_type(), octave_value::is_real_type(), octave_value::is_single_type(), octave_value::matrix_value(), octave_value::octave_idx_type_vector_value(), print_usage(), base_qr< qr_type >::Q(), Q, Matrix::row(), FloatMatrix::row(), ComplexMatrix::row(), FloatComplexMatrix::row(), octave_value::rows(), and x.
DEFUN_DLD | ( | qrdelete | , |
args | |||
) |
Definition at line 1161 of file qr.cc.
References check_index(), check_qr_dims(), octave_value::complex_matrix_value(), FloatQR::delete_col(), ComplexQR::delete_col(), FloatComplexQR::delete_col(), QR::delete_col(), FloatQR::delete_row(), ComplexQR::delete_row(), FloatComplexQR::delete_row(), QR::delete_row(), error(), octave_value::float_complex_matrix_value(), octave_value::float_matrix_value(), get_qr_r(), octave_value::is_numeric_type(), octave_value::is_real_type(), octave_value::is_single_type(), octave_value::matrix_value(), octave_value::octave_idx_type_vector_value(), print_usage(), base_qr< qr_type >::Q(), and Q.
DEFUN_DLD | ( | qrshift | , |
args | |||
) |
Definition at line 1428 of file qr.cc.
References check_index(), check_qr_dims(), octave_value::complex_matrix_value(), error(), octave_value::float_complex_matrix_value(), octave_value::float_matrix_value(), get_qr_r(), octave_value::int_value(), octave_value::is_numeric_type(), octave_value::is_real_type(), octave_value::is_single_type(), octave_value::matrix_value(), print_usage(), base_qr< qr_type >::Q(), Q, FloatQR::shift_cols(), ComplexQR::shift_cols(), FloatComplexQR::shift_cols(), and QR::shift_cols().
|
static |
Definition at line 49 of file qr.cc.
References base_qr< qr_type >::R(), base_qr< qr_type >::regular(), and MatrixType::Upper.
Referenced by DEFUN_DLD().