Tag Info

Hot answers tagged

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

The phase (and length) of the eigenvectors is completely undetermined unless you specify extra conditions in addition to the eigenvalue equation. Given that you don't have any additional conditions, it's not surprising that there is no well-defined way to plot the real and imaginary parts of each eigenvector component. A simple condition that makes the ...


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


8

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


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


7

s = {x, y} /. Solve[a x + y == 7 && b x - y == 1, {x, y}][[1]] {8/(a + b), -((a - 7 b)/(a + b))} lsa = LinearSolve[{{a, 1}, {b, -1}}, {7, 1}] {8/(a + b), (-a + 7 b)/(a + b)} f = LinearSolve[{{a, 1}, {b, -1}}]; lsb = f[{7, 1}] // Simplify {8/(a + b), -((a - 7 b)/(a + b))} s == lsa == lsb // Simplify True Solve can handle a ...


7

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


6

I'll make this a response since it seems to be a popular topic today (it showed up independently on the Wolfram Community forum). One can usually do this by finding the eigenvectors for a random linear combination of the matrices. This works for nonderogatory matrices, that is, ones that do not have nontrivial blocks in their Jordan decomposition. In ...


6

Unfortunately the various Solve like functions don't show the same behavior concerning string-type variable names. Some do accept strings (e.g. NDSolve in version 9): NDSolve[{"x"'["t"] == 0.1*"x"["t"], "x"[0] == 1}, "x", {"t", 0, 1}] but others don't. For your case, Eliminate obviously doesn't, but you only need to convert those variables which you want ...


6

x = {3, 1} y = {2, 5} a Defer[x] + b Defer[y] /. First@Solve[a x + b y == {7, 11}, {a, b}] (* x + 2 y *) Note that the output is usable as such: evaluate it and you'll get the combination result. If only integer coefficients are desired, changing the Solve to something like: Solve[a x + b y == {7, 11} && {a, b} \[Element] Integers, {a, b}] ...


6

The compatibility information at Compatibility/tutorial/LinearAlgebra/MatrixManipulation says These functions were available in previous versions of Mathematica and are now available on the web at library.wolfram.com/infocenter/MathSource/6770: LinearEquationsToMatrices InverseMatrixNorm ConditionNumber You can download the original package ...


6

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


5

The problem here can arise because of numerical underflow which appears for sufficiently large dimension of the problem. Some numerically very small number multiplies the parameter "a" and therefore "a" does not appear in the "solution". Consider a simple example Define the matrix m (fill it with random numbers, here exponentially distributed) In[263]:= ...


5

The two eigenvalues are degenerate. In general whenever you have degenerate eigenvalues there is arbitrariness in how to select the eigenvectors. You can construct a constant vector from the two degenerate eigenvectors like so: m = Import["https://dl.dropboxusercontent.com/u/63413473/ExampleMatrix.mx"]; {evals, evecs} = Eigensystem[m, -2]; You can check ...


5

The LinearAlgebra package has been deprecated since Mathematica 5, and is no longer bundled with Mathematica 9 or newer. You can still download a part of it (which contains the MatrixConditionNumber function) at the URL that jtbandes gave in his answer. First, we need to load the package: (* Be sure to install the above linked package in a "LinearAlgebra" ...


5

Dense blocks One can split matrices by blocks and use these blocks as a dense matrices blockSize = 100; m1[a_] m2[b_] ^:= a.b; part = Developer`PartitionMap[If[Length@#@"NonzeroValues" > 0, m1@Normal@#, 0] &, a, {blockSize, blockSize}]; a2.u_ ^:= Flatten[Developer`ToPackedArray[ part.Developer`PartitionMap[m2, u, blockSize]], 1] I have ...


5

Ok, I'll go ahead and answer my own question. After some thinking I came up with this: getIntersection[l1_, l2_] := Module[{n, ker, coeffs}, ker = NullSpace[Transpose[Join[l1,l2]]]; n = Length[l1]; coeffs = Map[Function[v, v[[1 ;; n]]], ker]; Return [Map[Function[v, v.l1], coeffs]]; ]; Can this be made any faster?


5

Maybe MapThread gives the levelspec control you need: lst = {{{a, b}, {c, d}}, {{w, x}, {y, z}}}; g @@ MapThread[f, lst, 1] (* or just g @@ MapThread[f, lst] -- thanks: Mr.W *) (* g[f[{a,b},{w,x}],f[{c,d},{y,z}]] *) g @@ MapThread[f, lst, 2] (* g[{f[a,w],f[b,x]},{f[c,y],f[d,z]}] *) or, g @@ Thread[f @@ lst] (* g[f[{a,b},{w,x}],f[{c,d},{y,z}]] *) or ...


5

You can also use (a.b\[Transpose])\[Transpose] or, equivalently, Transpose[a.Transpose[b]] to get the same result. a = RandomReal[{0, 1}, {2, 8}]; b = RandomReal[{0, 1}, {2, 8, 2}]; c = a.# & /@ b; (* from Sjoerd's answer *) (a.b\[Transpose])\[Transpose] == c (* True *)


4

Manipulate[Row[{ Plot3D[2 x +3y + 3 x^2 +4 y^2 +5 x y,{x,0,100},{y,0,100}, BoxRatios->1,ImageSize->400, MeshFunctions->{#3&},Mesh->{{k}},MeshStyle->Directive[{Thick,Red}]], ContourPlot[2 x +3y + 3 x^2 +4 y^2 +5 x y==k,{x,0,100},{y,0,100}, ContourStyle->Directive[{Thick,Red}],ImageSize->400, ...


4

Ordering[Norm /@ Last @ N[Eigensystem[system]]]; gives you the ordering by norm. You can apply this on your eigenvalues and eigenvectors, e.g. Eigenvectors[system][[%]] EDIT To apply this on a list of matrices: (# &@Ordering[Norm /@ N[#]]) & /@ Eigenvectors[#] & /@ {mat1,mat2,...,matn}


4

This is a problem known as finding 'moments of moments'. Notation Define the power sum $s_r$: $$s_r=\sum _{i=1}^n X_i^r$$ Your problem only involves $s_1$. The Problem Let $\left(X_1,\ldots,X_n\right)$ denote a random sample of size $n$ from a population random variable $X$. The problem is to find: $$ E\Big [\Big (\frac1n\sum_{i=1}^n X_i\Big)^2\Big ...


4

This is a bit long for a comment. You can use a tandem of LinearSolve and NullSpace. But for exact problems this will, I'm fairly sure, use dense matrices. That takes you back to what Solve is doing anyway, under the hood. Assuming your inputs are integer or rationals you might avoid dense matrix algebra as follows. Use numerical methods to find a single ...


4

Update: after clarification I propose f[m_] := Block[{$Assumptions = Alternatives @@ Flatten@m ∈ Reals}, Conjugate[m[[1, 1]]] // Simplify] f[{{x, x^2}, {h[x], S[y]^2}}] (* x *) Previous test-based answer: From the documentation of MatrixQ Test if a matrix has real numeric entries: MatrixQ[{{Pi, Sin[1]}, {Cos[2], E}}, Im[#] == 0 &] ...


4

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.


4

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


4

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


4

Matrix multiplication is built in in Mathematica. Just use the dot for multiplication. Here are two 2x2 matrices a = PauliMatrix[1] b = PauliMatrix[3] (* Out[49]= {{0, 1}, {1, 0}} *) (* Out[50]= {{1, 0}, {0, -1}} *) Here's a product a.b (* Out[53]= {{0, -1}, {1, 0}} *) and here is the product of the same factors in reverse order b.a (* Out[52]= ...


4

This probably doesn't address the full scope of your question but for the particular example you could use MapThread and Apply: ex1 = {{a, b}, {c, d}}; ex2 = {{w, x}, {y, z}}; g @@ MapThread[f, {ex1, ex2}] g[f[{a, b}, {w, x}], f[{c, d}, {y, z}]] Or Transpose and Apply: g @@ f @@@ ({ex1, ex2}\[Transpose]) g[f[{a, b}, {w, x}], f[{c, d}, {y, z}]]


4

You can use CoefficientArrays: xx = {a[0, 0], a[0, 0] + a[1, 0] + a[2, 0] + a[3, 0], a[0, 0] + a[0, 1] + a[0, 2] + a[0, 3], a[0, 0] + a[0, 1] + a[0, 2] + a[0, 3] + a[1, 0] + a[1, 1] + a[1, 2] + a[1, 3] + a[2, 0] + a[2, 1] + a[2, 2] + a[2, 3] + a[3, 0] + a[3, 1] + a[3, 2] + a[3, 3], a[1, 0], a[1, 0] + 2 a[2, 0] + 3 a[3, 0], a[1, 0] + a[1, ...



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