# Tag Info

16

Using the properties of Block matrices: $$\det\begin{pmatrix}\mathbf A&\mathbf B\\\mathbf C&\mathbf D\end{pmatrix}=\det(\mathbf A)\det\left(\mathbf D-\mathbf C\mathbf A^{-1}\mathbf B\right)$$ To visualize your matrix: mat1 = mat; {mat1[[;; 10, ;; 10]], mat1[[;; 10, 11 ;;]], mat1[[11 ;;, ;; 10]], mat1[[11 ;;, 11 ;;]]} = Range@4; (* cool :) *) ...

12

With the understanding that the criterion for including a point in the 3D matrix is that it has 3 unique domains in any of the 26 points surrounding a zero value in the watershed here is a simple way to extract the data. In the case where zero values in the watershed are in minority it may be the fastest approach to getting a list of points that fulfill the ...

11

Mathematica actually has a function purpose-built for the operation you're looking for. MatrixFunction[f, m] gives the matrix generated by the scalar function f at the matrix argument m. In your case, MatrixFunction[p, A] will return the 3-by-3 zero matrix, as desired.

11

The Pitsianis-Van Loan algorithm turns out to be surprisingly easy to implement in Mathematica: nearestKroneckerProduct[mat_?MatrixQ, dim1_?VectorQ, dim2_?VectorQ] /; TrueQ[Dimensions[mat] == dim1 dim2] := Module[{bv, cv, sig}, {bv, sig, cv} = SingularValueDecomposition[Flatten[ Map[Composition[Flatten, Transpose], ...

10

To verify that matrix is a zero of its characteristic polynomial, The Characteristic polynomial of the matrix is found, then evaluated for the matrix. The result should be the zero matrix. Clear[x] a = {{-1, -4, -2}, {0, 1, 1}, {-6, -12, 2}}; n = Length[a]; p = CharacteristicPolynomial[a, x]; (Sum[ Coefficient[p, x, i] MatrixPower[a, i], {i, 0, Exponent[p, ...

9

The order of eigenvalues is the most convenient order for the algorithm, which find these eigenvalues. You can always order them as you want very simply a = # + #\[Transpose] &@RandomReal[1, {10, 10}]; {ε, ψ} = Eigensystem[a]; {ε, ψ} = {ε[[#]], ψ[[#]]} &@ Ordering[ε]; Furthermore, the eigenvalues can be complex for non-Hermitian matrices. There is ...

9

The Susyno and LieART Mathematica packages can do this. I know best the first one (I wrote it), so let me use it as an example in this answer. Assuming that you have installed and loaded the package in a Mathematica session, your example ($\mathbf{10}\times\mathbf{27}$ in $SU(3)$) is computed as follows: ReduceRepProduct[SU3, {{3, 0}, {2, 2}}] This ...

9

There is another option, using the relatively new tensor capabilities of Mathematica. This is pretty much copied from another answer by jose, but I don't need any assumptions here: TensorExpand[KroneckerProduct[X, X] + KroneckerProduct[-X, X]] (* ==> 0 *) TensorExpand[KroneckerProduct[2 X, 3 Y]] (* ==> 6 KroneckerProduct[X, Y] *) There is a ...

8

You have to be a bit careful here; your last approach does not give the desired matrix F: (LinearSolve[dV, dv] // Transpose).dV === dv False Then what does give the correct output? We can use the fact that for generic matrices $A$ and $B$ we have $A.B = (B^T.A^T)^T$ and write F = Transpose @ LinearSolve[Transpose @ dV, Transpose @ dv] And indeed, ...

8

Perhaps MatrixLog[ m ] / Log[2]

8

a = RandomReal[{0, 1}, {2, 8}]; b = RandomReal[{0, 1}, {2, 8, 2}]; a.# & /@ b {{{2.58906, 3.35618}, {2.5578, 3.12812}}, {{1.3762, 2.87723}, {1.56668, 3.04675}}}

8

You are correct to say that this is a problem with the precision of the numbers involved. You can set the precision of those numbers explicitly: SetPrecision[{{3.9999999999998025*^14 + 0.001*I, 3.141592653589793 - 3.1405926535897932*I}, {3.141592653589793 - 3.1405926535897932*I, 3.9999999999998025*^14 + 0.001*I}}, 20]; Eigenvalues[%] (* ...

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

8

I needed this decomposition to answer another question, so I broke down and implemented it myself. The code is more or less a straightforward translation of the pseudocode in Golub/Van Loan: LDLT[mat_?SymmetricMatrixQ] := Module[{n = Length[mat], mt = mat, v, w}, Do[ If[j > 1, w = mt[[j, ;; j - 1]]; v = ...

7

As Nasser pointed out, the polar decomposition of a matrix is not pre-built into Mathematica, but it can be easily computed from the singular value decomposition. For reference, here is a method to do it: polarDecomposition[m_] := {#.#3\[ConjugateTranspose], #3.#2.#3\[ConjugateTranspose]} & @@ SingularValueDecomposition[m]; This tests that it actually ...

7

You are apparently looking for a way to reliably compare two numerical matrices by using their eigensystems. This can always be done for normal matrices by using the eigenvectors to construct their spectral decomposition. To do that, you shape the eigenvectors into the equivalent system of projectors. Then you can compare the projectors instead. The good ...

7

Here is an approach that might work out. Use GroebnerBasis to set up all polynomial relations, then reduce to see where there may be linear dependencies. We use surrogate variables to define algebraic relations for roots and reciprocals, so sx stands in for sqrt(x) below, and similar for the reciprocal variables xr1 and sxr2. We also use new variables to ...

7

Matlab is the fertile soil of bad Mathematica programming... try baseGenerator2[m_Integer, n_Integer] := Reverse@Sort[Join @@ Permutations /@ IntegerPartitions[n, {m}, Range[n, 0, -1]]] And for your own sanity, don't use uppercase initials on symbols - you may very well clash with built-ins and/or create debugging nightmares (e.g. N is a built-in, by ...

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

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

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 *)

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

7

\$MachinePrecision is different from MachinePrecision. The former calls for an arbitrary precision calcluation, done at the same precision as the machine-precision one. The main reason one would want to use this is to enable precision tracking, which is absent for a true machine-precision calculation using MachinePrecision. And, there is your answer. ...

6

Here's a simple way to enumerate all the conditions: fs = {x, y, z, 0}; conds = Table[{Equal @@ fs1, And @@ Table[First@fs1 >= f, {f, Complement[fs, fs1]}]}, {fs1, Subsets[fs, {2}]}] (* {{x == y, x >= 0 && x >= z}, {x == z, x >= 0 && x >= y}, {x == 0, x >= y && x >= z}, {y == ...

6

Experimentation based on the documentation you quoted led to two valid Method options: MatrixExp[{{1.2, 5.6}, {3, 4}}, Method -> "Pade"] {{346.557, 661.735}, {354.501, 677.425}} MatrixExp[{{1.2, 5.6}, {3, 4}}, {1, 2}, Method -> "Krylov"] {1670.03, 1709.35} If "Krylov" is used for the single parameter syntax it complains: MatrixExp[{{1.2, ...

6

As @Guess who it is. states in the comments, an overdetermined linear problem can be solved using Mathematica's LeastSquares[] functionality. To input your above system of equations: a = {{1, -2, 2, 2, 0, -2}, {1, -2, 2, -2, 0, 2}, {1, -2, -2, -2, -4, -2}, {1, 2, 2, -2, -4, -2}, {1, 2, -2, -2, 0, 2}, {1, 2, -2, 2, 0, -2}, {1, -2, -2, 2, 4, ...

5

Here is another solution, of course similar to that of wxffles, but using SolveAlways. The function takes any polynomial in one variable as argument and returns the list of coefficients. bernsteincoefficients[pol_] := Module[{t, n, a}, t = Variables[pol][[1]]; n = Exponent[pol, t]; Table[a[k], {k, 0, n}] /. SolveAlways[Sum[a[k] Binomial[n, k] ...

5

I'm not aware of any built in function, but here's one way to do it. bb[n_, k_, t_] := Binomial[n, k] t^(n - k) (1 - t)^k; A test cubic, and a sum of our basis functions: p = -(1/12) + (5 x)/8 - (17 x^2)/12 + x^3; s = Sum[a[k] bb[3, k, x], {k, 0, 3}] Now solve for the coefficients: Solve@Table[Coefficient[s, x, k] == Coefficient[p, x, k], {k, 0, 3}] ...

5

The magical words are Singular Value Decomposition. The singular vectors corresponding to small singular values form the kernel. Of course, Singular Value Decomposition is available in Mathematica as SingularValueDecomposition[]. As confirmed by Daniel Lichtblau, the built-in Tolerance option to NullSpace[] does it this exact way.

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