Tag Info

Hot answers tagged

8

m = {{1, 2, 3}, {2, 4, 1}, {2, 5, 7}}; {lu, p, c} = LUDecomposition[m]; l = lu SparseArray[{i_, j_} /; j < i -> 1, {3, 3}] + IdentityMatrix[3]; u = lu SparseArray[{i_, j_} /; j >= i -> 1, {3, 3}]; l.u == m[[p]] (* True *) l.u is equal to a permutation of the rows of m MatrixForm /@ {l, u}


8

As I have previously noted, QRDecomposition[] is by default set to return the so-called "thin QR" or "economy QR" decomposition; this is often the form desired in applications, since the triangular factor does not have the unneeded zero rows. MATLAB's qr(), by contrast, returns the full QR decomposition by default, and the economy QR through an option ...


7

The relationship between Q and R as computed by QRDecomposition and the "full QR" results (as described by Guesswhoitis} can be found in, for instance, Wikipedia. The following illustrates how to go from the Mathematica to the Wikipedia formulation. With a as defined in the question, {q, r} = QRDecomposition[a] (* {{{1/Sqrt[5], 0, 2/Sqrt[5]}, ...


5

As noted in the docs for LUDecomposition[], the two triangles are by default returned together as a single array; this is customary for LU decomposition routines, as in the original LINPACK and MATLAB's lu(). In fact, exactly this same format is stored internally by the LinearSolveFunction[] returned by LinearSolve[]: a = {{1, 2, 3}, {2, 4, 1}, {2, 5, 7}}; ...


2

Using @Guess comment answer, but spelled out in more detail: a = {{1, -3, 2, -2}, {3, -2, 0, -1}, {2, 36, -28, 27}, {1, -3, 22, 5}}; L = {{1, 0, 0, 0}, {b, 1, 0, 0}, {c, d, 1, 0}, {e, f, g, 1}}; U = {{1, -3, 2, -2}, {0, h, i, j}, {0, 0, k, l}, {0, 0, 0, m}}; result = {L, U} /. First @ Solve[L.U == a]; MatrixForm /@ result Note that matrix multiplication ...



Only top voted, non community-wiki answers of a minimum length are eligible