⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mf_qrsolve.hlp

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 HLP
字号:
{smcl}
{* 25mar2005}{...}
{cmd:help mata qrsolve()}
{hline}
{* index solve AX=B}{...}
{* index qrsolve()}{...}
{* index _qrsolve()}{...}
{* index LAPACK}{...}

{title:Title}

{p 4 8 2}
{bf:[M-5] qrsolve() -- Solve AX=B for X using QR decomposition}


{title:Syntax}

{p 8 12 2}
{it:numeric matrix}
{cmd:qrsolve(}{it:A}{cmd:,}
{it:B}{cmd:)}

{p 8 12 2}
{it:numeric matrix}
{cmd:qrsolve(}{it:A}{cmd:,}
{it:B}{cmd:,} {it:rank}{cmd:)}

{p 8 12 2}
{it:numeric matrix}
{cmd:qrsolve(}{it:A}{cmd:,}
{it:B}{cmd:,} {it:rank}{cmd:,} {it:tol}{cmd:)}


{p 8 12 2}
{it:real scalar}{bind:  }
{cmd:_qrsolve(}{it:A}{cmd:,}
{it:B}{cmd:)}

{p 8 12 2}
{it:real scalar}{bind:  }
{cmd:_qrsolve(}{it:A}{cmd:,}
{it:B}{cmd:,} {it:tol}{cmd:)}


{p 4 8 2}
where

{p 24 24 2}
		{it:A}:  {it:numeric matrix}

{p 24 24 2}
		{it:B}:  {it:numeric matrix}

{p 21 24 2}
	     {it:rank}:  irrelevant; {it:real scalar} returned

{p 22 24 2}
	      {it:tol}:  {it:real scalar}


{title:Description}

{p 4 4 2}
{cmd:qrsolve(}{it:A}{cmd:,} {it:B}{cmd:,} ...{cmd:)}
uses QR decomposition to solve {it:A}{it:X}={it:B} and returns {it:X}.
When {it:A} is singular or nonsquare, {cmd:qrsolve()} computes a least-squares
generalized solution.  When {it:rank} is specified, in it is placed the rank
of {it:A}.

{p 4 4 2}
{cmd:_qrsolve(}{it:A}{cmd:,} {it:B}{cmd:,} ...{cmd:)},
does the same thing, except that it destroys the contents of {it:A} and 
it overwrites {it:B} with the solution.  Returned is the rank of {it:A}.

{p 4 4 2}
In both cases, {it:tol} specifies the tolerance for determining whether 
{it:A} is of full rank.  {it:tol} is interpreted in the standard way -- 
as a multiplier for the default if {it:tol}>0 is specified, and as 
an absolute quantity to use in place of the default if {it:tol}<=0 
is specified; see {bf:{help m1_tolerance:[M-1] tolerance}}.


{title:Remarks}

{p 4 4 2}
{cmd:qrsolve(}{it:A}{cmd:,} {it:B}{cmd:,} ...{cmd:)} is suitable for use with
square, possibly rank-deficient matrix {it:A}, or when {it:A} has more rows
than columns.  When {it:A} is square and full rank, {cmd:qrsolve()} returns
the same solution as {bf:{help mf_lusolve:[M-5] lusolve()}}, up to roundoff
error.  When {it:A} is singular, {cmd:qrsolve()} returns a generalized
(least-squares) solution.

{p 4 4 2}
Remarks are presented under the headings

	{bf:Derivation}
	{bf:Relationship to inversion}
	{bf:Tolerance}


{title:Derivation}

{p 4 4 2}
We wish to solve for {it:X}

		{it:A}{it:X} = {it:B}{right:(1)    }

{p 4 4 2}
Perform QR decomposition on {it:A} so that we have {it:A} =
{it:Q}{it:R}{it:P}{bf:'}.  Then (1) can be rewritten

		{it:QRP}{bf:'}{it:X} = {it:B}

{p 4 4 2}
Premultiplying by {it:Q}{bf:'} and remembering that 
{it:Q}{bf:'}{it:Q} = {it:Q}{it:Q}{bf:'} = {it:I},
we have 

		{it:RP}{bf:'}{it:X} = {it:Q}{bf:'}{it:B}{right:(2)    }

{p 4 4 2}
Define 

		{it:Z} = {it:P}{bf:'}{it:X}{right:(3)    }

{p 4 4 2}
Then (2) can be rewritten

		{it:RZ} = {it:Q}{bf:'}{it:B}{right:(4)    }

{p 4 4 2}
It is easy to solve (4) for {it:Z} because {it:R} is upper triangular.
Having {it:Z}, we can obtain {it:X} via (3), because 
{it:Z} = {it:P}{bf:'}{it:X}, premultiplied by {it:P} and remembering 
{it:P}{it:P}{bf:'}={it:I}, yields

		{it:X} = {it:P}{it:Z}

{p 4 4 2}
For more information on QR decomposition, see {bf:{help mf_qrd:[M-5] qrd()}}.


{title:Relationship to inversion}

{p 4 4 2}
For a general discussion, 
see {it:Relationship to inversion} in {bf:{help mf_lusolve:[M-5] lusolve()}}.

{p 4 4 2}
For an inverse based on QR decomposition, see 
{bf:{help mf_qrinv:[M-5] qrinv()}}.
{cmd:qrinv(}{it:A}{cmd:)} amounts to 
{cmd:qrsolve(}{it:A}{cmd:,} {cmd:I(rows(}{it:A}{cmd:)))}, although it is 
not actually implemented that way.


{title:Tolerance}

{p 4 4 2}
The default tolerance used is 

		{it:eta} = 1e-13 * trace(abs({it:R}))/rows({it:R})

{p 4 4 2}
where {it:R} is the upper-triangular matrix of the QR decomposition;
see {it:Derivation} above.
When {it:A} is less than full rank, by say {it:d}
degrees of freedom, then {it:R} is also rank deficient by {it:d} degrees of
freedom and the bottom {it:d} rows of {it:R} are essentially zero.  If the
{it:i}th diagonal element of {it:R} is less than or equal to {it:eta}, then
the {it:i}th row of {it:Z} is set to zero.
Thus if the matrix is singular, {cmd:qrsolve()} provides a generalized
solution.

{p 4 4 2}
If you specify {it:tol}>0, the value you specify is used to multiply {it:eta}.
You may instead specify {it:tol}<=0, and then the negative of the value you
specify is used in place of {it:eta}; see 
{bf:{help m1_tolerance:[M-1] tolerance}}.


{title:Conformability}

    {cmd:qrsolve(}{it:A}{cmd:,} {it:B}{cmd:,} {it:rank}{cmd:,} {it:tol}{cmd:)}:
	{it:input:}
		{it:A}:  {it:m x n}, {it:m}>={it:n}
		{it:B}:  {it:n x k}
	      {it:tol}:  1 {it:x} 1    (optional)
	{it:output:}
             {it:rank}:  1 {it:x} 1    (optional)
	   {it:result}:  {it:n x k}

    {cmd:_qrsolve(}{it:A}{cmd:,} {it:B}{cmd:,} {it:tol}{cmd:)}:
	{it:input:}
		{it:A}:  {it:m x n}, {it:m}>={it:n}
		{it:B}:  {it:m x k}
	      {it:tol}:  1 {it:x} 1    (optional)
	{it:output:}
		{it:A}:  0 {it:x} 0
		{it:B}:  {it:n x k}
	   {it:result}:  1 {it:x} 1


{title:Diagnostics}

{p 4 4 2}
{cmd:qrsolve(}{it:A}{cmd:,} {it:B}{cmd:,} ...{cmd:)} 
and
{cmd:_qrsolve(}{it:A}{cmd:,} {it:B}{cmd:,} ...{cmd:)} 
return a result containing missing if 
if {it:A} or {it:B} contain missing values.

{p 4 4 2}
{cmd:_qrsolve(}{it:A}{cmd:,} {it:B}{cmd:,} ...{cmd:)} 
aborts with error if {it:A} or {it:B} are views.


{title:Source code}

{p 4 4 2}
{view qrsolve.mata, adopath asis:qrsolve.mata},
{view _qrsolve.mata, adopath asis:_qrsolve.mata}


{title:Also see}

{p 4 13 2}
Manual:  {hi:[M-5] qrsolve()}

{p 4 13 2}
Online:  help for 
{bf:{help mf_qrinv:[M-5] qrinv()}},
{bf:{help mf_qrd:[M-5] qrd()}},
{bf:{help mf_solvelower:[M-5] solvelower()}},
{bf:{help mf_cholsolve:[M-5] cholsolve()}},
{bf:{help mf_lusolve:[M-5] lusolve()}},
{bf:{help mf_svsolve:[M-5] svsolve()}},
{bf:{help mf_solve_tol:[M-5] solve_tol()}};
{bf:{help m4_matrix:[M-4] matrix}}
{p_end}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -