Tag Info

Hot answers tagged

7

The following function, along the lines of the suggestion by Guesswhoitis, produces what you appear to want. m[r_] := SparseArray[{Band[{1, 1}] -> n, Band[{2, 1}] -> -2, Band[{1, 2}] -> -2}, {r, r}] It is unclear whether the n in the picture is the same as n, the dimension of the matrix. (Do not use N, which is a reserved term.) If not, change ...


7

In Mathematica, the type of variable is interpreted based on the context, and if there are no values associated with the variable, then often nothing is done. When you write PauliMatrix[1].f, since there are no values/rules associated with f, this just returns {{0, 1}, {1, 0}}.f because the function Dot doesn't evaluate unless the arguments are vectors, ...


4

Matrices (and also vectors and other tensors) are multipled using Dot. Using your code, just replace * by . (I also removed all ('s and )'s as they don't do anything in this context. {{x, y, 1}}.{{a, b/2, d/2}, {b/2, c, e/2}, {d/2, e/2, f}}.{{x}, {y}, {1}} Result:


4

Look at what you get when you do e.g. f[1,1,1] and Conjugate[f[1,1,1]]. As the docs for Conjugate state, "Conjugate does not always propagate into arguments", and here it does not propagate into Cos and Sin. A solution seems to be to do f[kx_, ky_, t_] := -t E^(-I kx a) (1 + 2 E^(I (3 kx a)/2)*Cos[Sqrt[3]/2 ky a]); BlockA[kx_, ky_, t_] := ...


3

You For syntax is just wrong. Try r = Range[10] For[i = 1, i <= 9, i++, k = Complement[r, {i, i + 1}]; Print[k]] and avoid capital letters for your symbol names. K has a build-in meaning Information[K] K is a default generic name for a summation index in a symbolic sum.


2

Changing B*list to B.list seems to solve the problem. Also, I recommend dropping unnecessary decimal points from myfun14. Doing so gives (* {x[1] -> 0.5, x[2] -> 0.273438, x[3] -> 0.0128174, x[4] -> 0.125601, x[5] -> 0.00588754, x[6] -> 0.000275978, x[7] -> 0.0000129365, x[8] -> 0.0625006, x[9] -> 0.00292972, x[10] ...


2

Another approach is to use DiagonalMatrix and its optional third argument n = 5; mat[n_]:= DiagonalMatrix[ConstantArray[n, n]] + DiagonalMatrix[ConstantArray[-2, n - 1], 1] + DiagonalMatrix[ConstantArray[-2, n - 1], -1];


2

Assuming bbgodfrey's interpretation, I'd also expect this to be faster if dimension is large: ToeplitzMatrix[PadRight[{#, -2}, #]] & Though more memory hungry, it produces a packed array, so depending on what you're doing, it may have some performance benefits in use compared to a sparse realization (but the reverse could also be true, again, depends ...


2

Yes. But don't assume that the vertex named 1 is the first one, etc. That is often not the case. You can get the order of vertices using VertexList. You can get the index of a certain vertex using VertexIndex.


1

I am going to demonstrate this will a smaller matrix to enable us to more readily view the results. A0 = Table[Subscript[a, i, j], {i, 8}, {j, 8}]; A0//MatrixForm Step 1. Partition A0 into 4x4 blocks A0byBlock = Partition[A0, {4, 4}]; A0byBlock // MatrixForm Step 2. Map f onto A0 at level 2 A0out = Map[f, A0byBlock, {2}]; A0out // MatrixForm ...


1

A For-loop is a poor choice for your calculation in Mathematica. Better, because it's simpler and faster, is sets = Table[Complement[Range[10], {i, i + 1}], {i, 9}]; which has the additional advantage that the results are available for further calculations. To get the results printed out nicely, use Column Column @ sets



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