Use qrfact() (or the in-place version). It doesn't return [Q,R,P] because
Julia is smarter than that. It returns a specially designed type for the QR
return. It holds all of the those parts so you can get Q, R, and P out, but
most of the time you won't need to. For example, if A is the return of
qrfact, then A\b will automatically dispatch to do the fast algorithm for a
QR-factored matrix (which is the most common use for accessing Q and R).
On Tuesday, September 6, 2016 at 6:37:59 PM UTC-7, Stuart Brorson wrote:
>
> Hello Julia users,
>
> Matlab has a variant of the QR decomposition invoked like this:
>
> [Q,R,P] = qr(A)
>
> This variant of qr() returns matrix R where the diagonal elements are
> sorted from largest to smallest magnitude as you go from upper left to
> lower right. The matrix P is the permutation matrix which permutes
> the rows/cols of A to give this ordering of the diagonal elements of
> R. That is, Q*R = A*P.
>
> I tried doing the naive, analogous thing in Julia, but get an error:
>
> julia> A = rand(3,3)
> 3x3 Array{Float64,2}:
> 0.243071 0.454947 0.89657
> 0.112843 0.802457 0.375417
> 0.154241 0.0182734 0.992542
>
> julia> Q,R,P = qr(A)
> ERROR: BoundsError: attempt to access (
> 3x3 Array{Float64,2}:
> -0.786117 0.0985642 -0.610168
> -0.364946 -0.870763 0.329523
> -0.498833 0.481723 0.720492,
>
> 3x3 Array{Float64,2}:
> -0.309204 -0.659611 -1.33693
> 0.0 -0.645106 0.2396
> 0.0 0.0 0.29177)
> at index [3]
> in indexed_next at tuple.jl:21
>
> My question: What's the best way to get the equivalent of Matlab's
> [Q,R,P] = qr(A) in Julia? Should I write my own qr() (not too
> difficult)? Or just do some row/col permutation of the output of
> regular qr()?
>
> Thanks for any advice,
>
> Stuart
>
> p.s. I am using Version 0.4.3-pre+6 (2015-12-11 00:38 UTC)
>