New answers tagged

0

Thank you to @MarcoB for the solution in the comments! It ended up making the code significantly faster and use far less memory. To give some detail about precisely what I did, let me first reiterate the problem. The function I want to maximize is the determinant of a matrix, where the matrix is defined symbolically and each row has functions of a different ...


0

Similarly to my answer to your other question, it looks like support for recognizing this property was added in M11.2 or M11.3. In M11.1 I get: $Assumptions = t ∈ Complexes && A ∈ Matrices[{n,n}]; Id = IdentityMatrix[n]; (KroneckerProduct[A.A.A,Id]+KroneckerProduct[-2 t A.A,Id]).KroneckerProduct[A+3 t Id,4 t A.A]//TensorExpand; Coefficient[%,t^3] ...


3

It looks like support for recognizing this property was added in M11.2 or M11.3. In M11.1 I get: Assuming[ (a|b|c) ∈ Reals && (X|Y) ∈ Matrices[{n,n}], TensorExpand[ KroneckerProduct[IdentityMatrix[n],a X].(b KroneckerProduct[c IdentityMatrix[n],Y]) ] ] KroneckerProduct[IdentityMatrix[n], a X].(b KroneckerProduct[c ...


6

Use TensorExpand[] instead: Assuming[a ∈ Complexes && X ∈ Matrices[{n, n}], TensorExpand[(a X).(a IdentityMatrix[n])]] a^2 X


2

Algorithm There is no way to simplify the square root and recover the sign. Use a different algorithm. According to the wikipedia the Pfaffian can be computed as follows: Pf[x_] := Module[{n = Dimensions[x][[1]]/2}, I^(n^2) Exp[ 1/2 Total[ Log[ Eigenvalues[ Dot[KroneckerProduct[PauliMatrix[2], IdentityMatrix[n]], x]]] ]] ] ...


7

Not all matrices have a square root matrix, but you can try: Rho = {{Wxx, Wxy, Wxz}, {Wyx, Wyy, Wyz}, {Wzx, Wzy, Wzz}}; MatrixPower[Rho, 1/2] You can achieve the same result through diagonalization of Rho into $V\Lambda V^{-1}$ then taking the square root of the eigenvalues to give $V\Lambda^{1/2} V^{-1}$: val = Eigenvalues[Rho]; vec = Eigenvectors[Rho]; (...


1

You can find one possible solution with FindInstance. For example, operating in $N$=m dimensions (as N is a reserved keyword in Mathematica) and using n vectors, m = 3; n = 4; V = RandomVariate[NormalDistribution[], {n, m}] (* the vectors v_i *) (* {{0.512956, -2.44836, 1.64427}, {0.893093, -1.62577, -0.0144412}, {1.2746, 0.678006, -1....


2

On Mathematica 12.1 I can get the Eigenvectors and Eigenvalues. I noticed each eigenvalue was 1/3 times some Root expression so I created some replacement rules to express the eigenvectors in terms of the $\mu_i$ m = {{p3 + p8/Sqrt[3], p1 - I p2, p4 - I p5}, {p1 + I p2, -p3 + p8/Sqrt[3], p6 - I p7}, {p4 + I p5, p6 + I p7, -((2 p8)/Sqrt[3])}}; eval ...


3

Since symbolic calculations are better done with exact, rather than floating-point, numbers, the following was done with t = 1/10: Eigenvalues[ham // ExpToTrig] (* { 0, -Sqrt[2 + Cos[kx] + Cos[ky]]/(5 Sqrt[2]), Sqrt[2 + Cos[kx] + Cos[ky]]/(5 Sqrt[2])} *) Note: It will "work" with t = 0.1 but the factor in the denominator gets incorporated as Real ...


1

I'll post an answer to an extremely closely related problem which I took some time sorting out today. If I have some $2n \times 2n$ matrix $J = \begin{pmatrix} 0 & - I \\ I & 0 \end{pmatrix}$ J = KroneckerProduct[{{0,-1},{1,0}},IdentityMatrix[n]] and a second $2n \times 2n$ matrix $H$ which satisfies $$ J H J = -H^* $$ for example H = ...


3

Try TensorReduce $Assumptions = {A ∈ Matrices[{n, n}], B ∈ Matrices[{n, n}]}; expr = Commutator[A + B, Commutator[A + B, A - B]] - Commutator[A - B, Commutator[A + B, A - B]]; TensorReduce[expr] (* A.MatrixPower[A - B, 2] + 2 A.MatrixPower[B, 2] + A.MatrixPower[A + B, 2] + B.MatrixPower[A - B, 2] - B.MatrixPower[A + B, 2] + 6 MatrixPower[B, 2].A - 6 ...


1

May be this code could be supportive vm = {{{0.10402567469787839`, 0.05634724046135078`, 0., 0.06671318616834762`}, {-0.033304268882567746`, 0.061484804090894324`, 0.09542953968274223`, -0.10079092470343654`}, \ {0.045451481623891156`, -0.08391042761333754`, 0.06992535634444795`, -0.030220722382910785`}, {0.`, 0.`, 0.`, 1.`}}, ...


2

A less general solution for the case of spin chains and sparse arrays I faced the problem of finding reduced density matrices for large spin systems, where the Hamiltonian is represented as a $2^N$ by $2^N$ matrix and state vectors are represented as vectors of length $2^N$. You could also have $D$ states per site for a state space of $D^N$, but I'll use $D=...


5

For the posted example, TensorReduce does the trick: TensorReduce[ Transpose[Transpose[A].Transpose[B]], Assumptions -> {A ∈ Matrices[{m, n}], B ∈ Matrices[{k, m}]} ] B.A


1

It is not always advised to perform LU decomposition without pivoting, for tridiagonal matrices or otherwise. Nevertheless, whenever it is stable (e.g. diagonally dominant cases), there is a simple formula for the $\mathbf L$ and $\mathbf U$ factors, based on the usual three-term recurrence for the determinant of a tridiagonal matrix (see e.g. this). In ...


4

I've decided to write another answer, as the following generalizes the companion matrices featured in my other answer. De Terán, Dopico, and Mackey, in their paper, show a method to construct a generalized Fiedler companion matrix, which has the Frobenius and Fiedler matrices in my other answer as special cases. Here is a Mathematica implementation of their ...


9

Plot[Evaluate[Eigenvalues[M1]], {t, 0, 10}, PlotLegends -> "Expressions"] sumofnegativeeigenvalues = Total @ - Ramp @ - Eigenvalues[M1] -2 Ramp[30 - t] - Ramp[1/2 (-1 - 7 t - Sqrt[1 - 6 t + 9 t^2 + 4 t^4])] - Ramp[1/2 (-1 - 7 t + Sqrt[1 - 6 t + 9 t^2 + 4 t^4])] Plot[sumofnegativeeigenvalues, {t, 0, 10}, AxesOrigin -> {0, 0}] Alternatively, ...


3

RiccatiSolve and DiscreteRiccatiSolve can handle symbolic matrices as long as the eigenvalues of the Hamiltonian are numeric so that the solver can determine those on the left- and right-half planes. In this case aa = {{1, 0}, {0, 1}}; bb = {{1, 0}, {0, a}}; qq = {{1, 0}, {0, 1}}; rr = {{1, 0}, {0, 1}}; and the eigenvalues of the Hamiltonian matrix are ...


3

ClearAll[partialTranspose] partialTranspose = ArrayFlatten @ Map[Transpose, #, {2}] &; mat = Array[Subscript[ρ, Row @ {##}] &, {8, 8}]; MatrixForm[mat] mat24 = Partition[mat, {2, 2}]; mat42 = Partition[mat, {4, 4}]; Row[MatrixForm /@ {mat, mat24, partialTranspose @ mat24}, Spacer[10]] Row[MatrixForm /@ {mat, mat42, partialTranspose @ mat42}, ...


4

As stated in the Details section of the Eigensystem and Eigenvectors help page, the eigenvectors will be normalized to 1 for approximate numerical matrices. Nubers like 3.5 are approximate numbers. Replace your numbers with exact numbers and it should give you more visually pleasing eigenvectors in most cases. Example: Eigensystem[{{3 + 8/10, 21, 21}, {3/...


1

You really should always look at result of each step you did to find the problem, and not at the last step. If you did, you'd seen the problem. You used [] instead of [[ ]] when calculating A X = Range[0, 0.9, 0.1]; M = Length[X]; Y = {0, 0.11723, 0.16527, 0.28996, 0.355861, 0.446146, 0.476244, 0.443929, 0.424399, 0.386496}; A = Table[X[[i]]^j, {i, 1, M}...


Top 50 recent answers are included