# qrfact(A)

``````..  qrfact(A) -> SPQR.Factorization

Compute the QR factorization of a sparse matrix ``A``. A fill-reducing permutation is used. The main application of this type is to solve least squares problems with ``\``. The function calls the C library SPQR and a few additional functions from the library are wrapped but not exported.``````

## Examples

The `qrfact(A, pivot=Val{false})` function computes the QR factorization of matrix `A`. The return type of `F` depends on the element type of `A` and whether pivoting is specified (with `pivot==Val{true}`). Here are some examples and explanations of its usage:

1. Compute QR factorization of a matrix:

``````julia> A = [1 2; 3 4; 5 6];
julia> F = qrfact(A)
QR{Float64,Array{Float64,2}} with factorizations Q and R:
Q factor:
3×3 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}:
-0.16903   0.897085  -0.408248
-0.507092  -0.276026  -0.816497
-0.845154   0.345033   0.408248
R factor:
2×2 Array{Float64,2}:
-5.91608  -7.43735
0.0       0.828078``````

This example computes the QR factorization of matrix `A` and stores the result in `F`. The `QR` object `F` contains the `Q` factor and the `R` factor.

2. Compute QR factorization with pivoting:

``````julia> A = [1 2; 3 4; 5 6];
julia> F = qrfact(A, pivot=Val{true})
QRPivoted{Float64,Array{Float64,2}} with factorizations Q, R, and P:
Q factor:
3×3 LinearAlgebra.QRPackedQ{Float64,Array{Float64,2}}:
-0.16903   0.897085  -0.408248
-0.507092  -0.276026  -0.816497
-0.845154   0.345033   0.408248
R factor:
2×2 Array{Float64,2}:
-5.91608  -7.43735
0.0       0.828078
P permutation:
3-element Array{Int64,1}:
3
2
1``````

This example computes the QR factorization of matrix `A` with pivoting enabled. The `QRPivoted` object `F` contains the `Q` factor, the `R` factor, and the permutation matrix `P`.

3. Access individual components of the factorization:

``````julia> Q = F[:Q]
3×3 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}:
-0.16903   0.897085  -0.408248
-0.507092  -0.276026  -0.816497
-0.845154   0.345033   0.408248

julia> R = F[:R]
2×2 Array{Float64,2}:
-5.91608  -7.43735
0.0       0.828078

julia> P = F[:P]
3-element Array{Int64,1}:
3
2
1``````

This example shows how to access the `Q`, `R`, and `P` components of the factorization `F`.