Tag Info

New answers tagged

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}}; ...


7

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]}, ...


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}


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 ...


0

There is a LUDecomposition function in Mathematica: a = {{1, -3, 2, -2}, {3, -2, 0, -1}, {2, 36, -28, 27}, {1, -3, 22, 5}}; n = Dimensions[a][[1]]; {LU, MP, MC} = LUDecomposition[a] LU = First[LUDecomposition[a]] L = LU * SparseArray[{i_, j_}/; j<i -> 1, {n, n}] + IdentityMatrix[n] U = LU * SparseArray[{i_, j_}/; j>=i -> 1, {n, n}] L.U


3

Just to separate this from a package-based answer. In Mathematica 10.2, you can now do this with the built-in function SmithDecomposition. So using the same matrix from my previous answer: mat = {{1, 2, 3}, {-2, 3, 1}, {3, 2, 1}}; MatrixForm /@ SmithDecomposition[mat] Where the second element is the Smith normal form.


4

As an extended side note, p = Map[KroneckerProduct[#, #] &] @ Map[Normalize] @ vecs; (* You can use Orthogonalize instead of Map[Normalize], too *) generates a projection matrix that projects any matrix onto your known subspace, and it can be used to subtract off that piece. Examining this matrix, p (* {{1, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0}, ...


7

b = {{1, 1, 0, 0, 0, 0}, {1, -1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 1}, {-1, -2, -3, -3, -3, -3/2}}; h = NullSpace@b (* {{0, 0, -1, 0, 1, 0}, {0, 0, -1, 1, 0, 0}} * MatrixRank@Join[b, h] (* 6 *)


2

[This is what Wolfram tech support told me when I filed a bug report:] That is because using machine precision (inexact) numbers such 0. (as opposed to exact numbers like 0) forces Eigenvectors[] to seach for eigenvectors numerically and hence the error message. For example, please evaluate and compare the results of the following expression used with ...


7

Update: it seems this only works in 10.1 and later, but not in 10.0. This works: Assuming[(a | b | c) ∈ Matrices[{d, d}], TensorExpand@Transpose[a.(b + c)]] (* Transpose[b, {2, 1}].Transpose[a, {2, 1}] + Transpose[c, {2, 1}].Transpose[a, {2, 1}] *) We needed to tell Mathematica that a, b and c are square matrices and use TensorExpand. Check here: ...


1

Simplify@Eigenvectors[{{Cos[0. + x], Exp[I x]}, {1, 0}}] $\left( \begin{array}{cc} e^{-1. i x} \left(-0.25 \sqrt{1.+2. e^{2 i x}+16. e^{3 i x}+e^{4 i x}}+0.25 e^{2. i x}+0.25\right) & 1. \\ 0.25 e^{-1. i x} \left(\sqrt{1.+2. e^{2 i x}+16. e^{3 i x}+e^{4 i x}}+e^{2. i x}+1.\right) & 1. \end{array} \right)$


2

I am not sure what a valid transpose of a StateSpaceModel is but here is an attempt: ssm = StateSpaceModel @ TransferFunctionModel[{{a^2/(s^2 + b s + c)}}, s] Transpose /@ #[[{1, 3, 2, 4}]] & /@ ssm


7

As indicated in the comments, machine-precision linear algebra operations in Mathematica use the Intel MKL library optimized implementation of BLAS/LAPACK. That is the case for all platforms where MKL is available: Windows, Linux and Mac OS X (there will be no obvious MKL library files present in the layout on OS X in 10.1 or later due to static linking). ...


1

For a numerical approximation you may try something like: M = {{s, ab, ac}, {ab, s, bc}, {ac, bc, s}}; disc = Discriminant[CharacteristicPolynomial[M, x], x] // FullSimplify f[e_] := 2 Norm[e]^-3 (1 - 3 Sin[θ]^2 Cos[φ - ArcTan[e[[1]], e[[2]]]]^2) Cos[{x, y}.e]; ab = f[{1, 0}]; ac = f[{0, 1}]; bc = f[{1, 1}] + f[{-1, 1}]; s = f[{2, 0}] + f[{0, 2}]; ...


2

As @GuessWhoItis mentioned, some or all of this can be done analytically. But I'll answer your question regarding Mathematica syntax, as it seems to be the goal of what you're trying to achieve here. Mathematica does not recognise "i" being a variable in "ci". The best way to deal with this is to define cVector=Table[c[i],{i,n}]; or alternatively, ...


1

\[GothicCapitalR] = {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}, {{0, 0, 1}, {1, 0, 0}, {0, 1, 0}}, {{1, 0, 0}, {0, 0, 1}, {0, 1, 0}}, {{0, 0, 1}, {0, 1, 0}, {1, 0, 0}}, {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}}; i = 1; j = 1; det = 1; a = Subsets[Range[6], {3}]; v = {x, y, z}; k = \[GothicCapitalR].v; PolynomialLCM @@ ...


4

Instead of While[i<21,...], use Table[...,{i,20}]. The ... part can be reduced to r = k[[a[[i]]]]; Factor[Det[r]] To find the PolynomialLCM, simply replace the head ( List) of the table with PolynomialLCM using Apply, or @@ for short: PolynomialLCM @@ Table[...,{i,20}]


2

Replace the Print[det] in the print with: Paste[det]


1

First of all, the desired result Composition[f1, f2][x] auto-evaluates to something slightly different: Composition[f1, f2][x] (* ==> f1[f2[x]] *) If that's OK with you, then I could simply re-use my answer to Having the derivative be an operator, without the first two lines in which I define the specific action of the operators as derivatives. So all ...



Top 50 recent answers are included