# Tag Info

7

Here's a better way to solve it I think. This avoids a lot of the issues in the FindInstance / NMinimize calculation I did earlier, and it's much more efficient: DrazinInverse[A_] := Module[{k = 0, Ak = IdentityMatrix@First@Dimensions@A, X, nxtA}, While[nxtA = Ak . A; MatrixRank[Ak] != MatrixRank[nxtA], Ak = nxtA; ++k ]; X = LinearSolve[nxtA, Ak]; ...

5

Here a version which doesn't uses Subscript' s: v = 800; b = 0.5; b = 1; g[n_, b_] := b Sinc[n Pi b] ; h[n_, b0_, b1_] := g[n, b1] - g[n, b0] H = Table[ KroneckerDelta[n, m] (n^2 + v*(b - b - h[2 m, b, b])) + v*(1 - KroneckerDelta[n, m])*(h[n - m, b, b] -h[n + m, b, b]) , {n, 1, 10}, {m, 1, 10}]; Eigensystem[H]

5

If it is only about the sums of negative entries, then yes. This is how we can do it without even building the tensor/Kronecker products: M = RandomReal[{-1, 1}, {3, 3}]; ClearAll[sumPositive]; ClearAll[sumNegative]; sumPositive = Total[Ramp[ M], TensorRank[M]]; sumNegative = Total[Ramp[-M], TensorRank[M]]; sumNegative[n_] := sumNegative[n] = Plus[ ...

4

This seems like a good job for Piecewise: q[i_, j_] := Piecewise[{{-b, j == i + d}, {c, j == i + 1}, {l, j == d + i + 1}, {l, j == d + i - 1}}] Now you can build the matrix: d = 8; n = 15; (mat = Array[q, {n, n}]) // MatrixForm which gives the same answer as cvgmt.

3

It's faster and cleaner not to use any For loops and use list processing whenever possible: nn = 6; x = Cos[Subdivide[nn]*Pi] (* {1, Sqrt/2, 1/2, 0, -1/2, -Sqrt/2, -1} *) d1 = Outer[Subtract, x, x] (* {{0, 1 - Sqrt/2, 1/2, 1, 3/2, 1 + Sqrt/2, 2}, {-1 + Sqrt/2, 0, -(1/2) + Sqrt/2, Sqrt/2, 1/2 + Sqrt/2, Sqrt, 1 + ...

3

crystalsystemnames = {"Cubic", "Tetragonal", "Orthorhombic", "Hexagonal", "Monoclinic", "Rhombohedral", "Triclinic"}; metrictensors = Partition[{g1, g2, g3, g4, g5, g6, g7}, 1]; data = MapThread[Append, {metrictensors, crystalsystemnames}]; MatrixForm[MapAt[MatrixForm, data, {All, 1}...

3

Maybe need to chack the definition of such matrix,it seems not right. d = 8; n = 15; q=SparseArray[{{i_, j_} /; j == i + 1 -> c, {i_, j_} /; j == i + d -> -b, {i_, j_} /; j == d + i + 1 || j == d + i - 1 -> l}, {n, n}] q//MatrixForm Or d = 8; n = 15; m = SparseArray[{Band[{1, 1+1}] -> c, Band[{1, 1 + d}] -> -b, Band[{1, d + 1 + 1}...

3

Export["matrix.csv", values, TableHeadings -> {paramc3, paramS}]

2

One of possible ways: out = Transpose@ Prepend[Transpose@Prepend[values, paramS], Prepend[paramc3, ""]] Export["matrix.csv", out, "CSV"]

2

Unprotect[Det]; Det[{{}}] = 1; Protect[Det]; Unprotect[Tr]; Tr[{{}}] = 0; Protect[Tr]; Unprotect[Transpose]; Transpose[{{}}] = {{}}; Protect[Transpose]; Problem is: What is the type of an empty matrix? Exact, integer, machine double...? In general, I do not recommend to mess with built-ins like this...

2

Probably not easier to understand than Table, but index- and dimension-free: Join[ Map[List, Values@DownValues@a, {2}], Map[List, Values@DownValues@b, {2}], Outer[List, mu, logo], 3] Variations are possible, such as this nifty one which uses the dimension 10: Values@DownValues@a === Array[a, 10] (* True *) One could then map List inside Array instead ...

2

This definition doesn't use SparseArray, but it should give it to you datamat = Table[{a[i][[j]], b[i][[j]], mu[[i]], logo[[j]]}, {i, 10}, {j, 9}]; For example, with $i=5$ and $j=9$, select all 4 corresponding values by evaluating datamat[[5,9]] (* {0.808423, 4988.96, 0.909091, 4} *). These four values are the 9th element of a, the 9th ...

2

Reevaluating with v12.3.1, I am able to reproduce the crossover. \$Version (* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *) Clear["Global*"] hamil[kx_, ky_, kz_] = {{-10.6, -0.25 E^(I (-0.625 kx - 0.21650635094610965 ky - 0.43666666666666665 kz)) - 0.7 E^(I (0.375 kx - 0.21650635094610965` ky - ...

2

Maybe this is a bit closer to what you want to do. RF = Table[ Plus[ f[d, b, a, c], Conjugate[f[c, a, b, d]], If[b == d, -Sum[f[a, i, i, c], {i, 1, n}], 0], If[a == c, -Conjugate[Sum[f[b, i, i, d], {i, 1, n}]], 0] ] , {a, 1, n}, {b, 1, n}, {c, 1, n}, {d, 1, n}]; Note that I use Plus instead of + only because it is more legible of ...

2

Here a more elementary example: n = 5; A = SparseArray[{Band[{1, 1}] -> 1, Band[{1, 2}] -> -1, {n, 1} -> -1}, {n, n}]; B = SparseArray[{Band[{1, 1}] -> 1, Band[{1, 2}] -> -1}, {n, n}]; 1./Divide @@ MinMax[Diagonal[SingularValueDecomposition[A][]]] 1./Divide @@ MinMax[Diagonal[SingularValueDecomposition[B][]]] ComplexInfinity 6.74204 ...

1

Unprotect[NonCommutativeMultiply]; NonCommutativeMultiply[0, a_] := 0; NonCommutativeMultiply[a_, 0] := 0; A = {{0, a, a, 0}, {b, 0, 0, a}, {b, 0, 0, a}, {0, b, b, 0}}; Table[ Sum[A[[i, k]] ** A[[k, j]], {k, 1, 4}] , {i, 1, 4}, {j, 1, 4}] {{2 a ** b, 0, 0, 2 a ** a}, {0, a ** b + b ** a, a ** b + b ** a, 0}, {0, a ** b + b ** a, a ** b + b ** a, 0}, {2 b ...

1

nodes = Union@Catenate@Keys@assoc edges = Cases[Normal@assoc, ({x_, y_} -> 1) :> x -> y] AdjacencyMatrix@Graph[nodes, edges] (* a SparseArray *)

1

For convenience, first define a function that creates the Ai with symbolic elements: n = 2; A[i_] := Array[(Subscript[a[i], #1, #2]) &, {n, n}] The rest is trivial, simply sum it up: Sum[A[i] t^i, {i, -5, 5}] An example for n=2. Note that result is a matrix where every element is a Laurent series:

1

Try with the following code: RowsSum[nmax_Integer?Positive, length_Integer?Positive, vector_List] := Module[ {matrix, matrixrows, s}, matrix = Table[i, {i, nmax}, {length}]; matrixrows[vector2_List, matrix_] := matrix[[vector]]; s = Flatten@Map[Total, List[matrixrows[vector, matrix]]]; Return[s]; ]; Test: RowsSum[12, 4, {1, 5, 9}] (*{15, 15, 15, 15}*) ...

1

For numerical values of the parameters it could be done as below. m[x_, y_, z_, w_, a_, b_, c_, d_, e_, f_] = {{a*Abs[x]^2 + 2*Re[e*x*Conjugate[y]] + c*Abs[y]^2, b*Abs[x]^2 + 2*Re[f*x*Conjugate[y]] + d*Abs[y]^2}, {a*Abs[z]^2 + 2*Re[e*x*Conjugate[y]] + d*Abs[y]^2, b*Abs[z]^2 + 2*Re[f*z*Conjugate[w]] + d*Abs[w]^2}}; Form the unitary matrix ...

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