QR decomposition and least squares

Source: Internet
Author: User

Main content:

1. Definition of QR decomposition

2. QR decomposition method

3. QR decomposition and least squares

4. MATLAB implementation

 

I. QR decomposition

The r decomposition method is one of the three ways to decompose a matrix. In this way, the matrix is decomposed into an orthogonal matrix and the product of an upper triangle matrix.

QR decomposition is often used to solve the linear least squares problem. QR decomposition is also the basis of a specific feature value algorithm, namely, the QR algorithm.

Definition:

Real Number MatrixAThe QR decomposition of isASplit into Q and R.QIs an orthogonal matrix (meaningQTQ=I) AndRIs the upper triangle matrix. Similarly, we can define the Ql, RQ, and SCSI decomposition of.

More generally, we can break down the plural number of factors.M×NMatrix (MN) IsM×NMatrix (inQ?Q=I) AndN×NThe product of the upper triangle matrix.

IfAThis factor is unique when we requireRIs a positive number.

Ii. Method of QR decomposition

There are many practical calculation methods for QR decomposition, such as Givens Rotation, Householder transformation, and Gram-Schmidt orthogonal transformation. Each method has its own advantages and disadvantages.

Iii. QR decomposition and least squares

Least Squares:

For a given data point {(XI, Yi)} (I = ,..., M), in the fixed function type Φ, evaluate p (x) ε Phi, and minimize the sum of squares of errors e ^ 2, E ^ 2 = Σ [P (XI) -Yi] ^ 2. In a geometric sense, it is to seek and give the fixed point {(XI, Yi)} (I = ,..., M) the sum of the squared distance is the smallest curve y = p (x ). The function p (x) is called the fitting function or the least squares solution. The method for finding the fitting function p (x) is called the least squares method for curve fitting.

The form of the matrix of the Least Square: Ax = B, where A is the NXK matrix, X is the column vector of kx1, and B is the column vector of Nx1. If N> K (the number of equations is greater than the number of unknowns), this system is called over determined system. If n <K (the number of equations is less than the number of unknowns ), this system is the under determined system.

Least Squares and QR decomposition:

Normally, there is no solution to this equation, but in the field of numerical calculation, we usually calculate min | Ax-B |, to solve X. The intuitive solution is to solve a' AX = a' B, but it is usually inefficient. One of the common solutions is to perform a QR decomposition (A = QR) on a, where Q is the NXK orthogonal matrix (orthonormal matrix ), R is the upper triangle matrix (upper triangular matrix) of kxk ), then min | Ax-B | = min | QRX-B | = min | RX-Q 'B |, use the MATLAB command x = r \ (Q' * B) to obtain X.

MATLAB Implementation of the least squares:

① Use polyfit (X, Y, 1) as the lift Function)

② Polynomial functions use polyfit (X, Y, n), n is the number of times

Fitting Curve

X = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0],

Y = [1.75, 2.45, 3.81, 4.80, 7.00, 8.60].

Solution: the MATLAB program is as follows:

X = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0];

Y = [1.75, 2.45, 3.81, 4.80, 7.00, 8.60];

P = polyfit (X, Y, 2)

X 1 = 0.5: 0.5: 3.0;

Y1 = polyval (p, X1 );

Plot (X, Y, '* R', X1, Y1,'-B ')

The calculation result is:

P = 0.5614 0.8287 1.1560

That is, the obtained polynomial is y = 0.5614x ^ 2 + 0.8287x + 1.15560.

③ Nonlinear functions use lsqcurvefit (fun, x0, x, y)

Iv. MATLAB Implementation of QR decomposition

[Q, R] = QR (A) or [Q, R] = QR (A, 0)(The difference between the two is self help or DOC)
Q indicates a regular orthogonal matrix,
R represents the upper triangle matrix.

In addition, the original matrix A does not need to be a square matrix. If the size of matrix A is N * m, the Q size of the matrix is N * m, and the R size of the matrix is M * m.

V. References:

Http://blog.sina.com.cn/s/blog_64367bb90100ikji.html

Http://www.360doc.com/content/13/1015/09/12712639_321543226.shtml

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.