Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Questions on the manipulation of matrices in Mathematica.
1
vote
Accepted
Constructing a special square matrix
Notice that the generated matrix is actually $(N+1)\times(N+1)$ as the indices run from 0 to $N$. You can see this in your images, which show an even-sized matrix for odd $N$ and vice-versa. … ,
{n + 1, n + 1}]
If you need a non-sparse matrix, use Normal.
I'm not sure why the bottom-right matrix element in your odd-$N$ image is zero. …
0
votes
Accepted
Wrong calculation with matrix exponential (MatrixExp)
,{60,62}->2,{61,59}->2,{61,61}->3,{62,60}->2,{62,62}->1,{62,63}->2,{63,62}->2,{63,63}->3,{64,64}->5}]/10;
we see that the commutator vanishes exactly,
A.B - B.A // Norm
0
With the numerical matrix …
2
votes
Accepted
Matrix definition using some rules for the elements
Assuming that you meant
$$
\langle n\lvert M \rvert m \rangle = m^2 \delta_{m,n}+(1-m)(\delta_{m,n+2}+\delta_{m,n-2})
$$
and ranges of $n,m\in\{1,2,3,\ldots,a\}$, you can define this matrix with
M[a … isn't Hermitian and that you are using Dirac-notation matrix elements, I suspect that there is something wrong in these definitions. …
1
vote
Solve Set of Linear Equations (Analytic)
an $n\times n$ symmetric matrix $M$:
M[n_Integer?Positive] := Array[m @@ Sort[{##}] &, {n, n}]
an $\vec{y}$-vector with only 1-elements:
y[n_Integer? …
11
votes
Accepted
Creating block diagonal matrix identity and one Pauli matrix
See this book on page 53 (section 3.4.1):
SpinQ[S_] := IntegerQ[2S] && S>=0
op[S_?SpinQ, n_Integer, k_Integer, a_?MatrixQ] /;
1<=k<=n && Dimensions[a] == {2S+1,2S+1} :=
KroneckerPro …
6
votes
Place matrix into a larger matrix filled with zeros
M = {{1, 1, 0}, {1, 0, 0}};
ArrayPad[M, {{0, Length[Transpose[M]]}, {Length[M], 0}}]
(* {{0, 0, 1, 1, 0},
{0, 0, 1, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 0 …
0
votes
Access specific value in matrix based on row/column information
data = {{0, 0, 0, 0}, {1, 2, 92.355, 49.}, {1, 7, 86.7407, 46.5},
{6, 2, 92.355, 49.}, {6, 7, 87.237, 46.5}};
FirstCase[data, {1, 7, x_, ___} -> x]
(* 86.7407 *)
6
votes
How can I check if the matrix is of the following form?
I'm assuming that the matrix can be of any size, and that $a$ can stand for anything:
check[u_] := DiagonalMatrixQ[u] &&
Apply[SameQ, Diagonal[u]*(-1)^Range[Length[u]]]
check @ {{-a, 0, …
6
votes
Calculation of the average of the values of a column in a matrix
matrixExample = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 9, 9, 9}};
Mean[matrixExample]
(* {5, 17/3, 19/3, 7} *)
% // N
(* {5., 5.66667, 6.33333, 7.} *)
10
votes
How can I build a symmetric matrix of up to 100?
Look up a Toeplitz matrix:
m[n_] := a^(ToeplitzMatrix[n]-1)
Alternatively, an explicit construction as a rule-based matrix:
m[n_] := SparseArray[{i_, j_} -> a^Abs[i - j], {n, n}]
and the same with the …
4
votes
Select unique row and column entry from an nxn matrix
14, 11, 3, 8, 7}, {4, 12, 19, 13, 3}};
f[p_] := Total[MapThread[Part, {A, p}]]
M = ResourceFunction["MaximizeOverPermutations"];
M[f, 5]
(* {{{4, 5, 2, 1, 3}}, 81} *)
Let's try it for a 20×20 matrix …
7
votes
How to rewrite a tensor as a matrix
X = {TensorProduct[{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}]/Sqrt[2]};
Flatten[X, {{1, 3, 5}, {2, 4, 6}}]
(* {{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, …
3
votes
Find The Value of a n-order Determinant
/. a[0] -> x]
(* (-x+a[1])(-x+a[2])(-a[1]+a[2])(-x+a[3])(-a[1]+a[3])(-a[2]+a[3])(-x+a[4])(-a[1]+a[4])(-a[2]+a[4])(-a[3]+a[4]) *)
This method is exponentially faster than actually building the matrix …
1
vote
Accepted
Writing equation of motion in matrix form
x[t_] = {x1[t], x2[t], x3[t], x4[t]};
A = {{-K, K, 0, 0}, {K, -k - K, k, 0}, {0, k, -k - K, K}, {0, 0, K, -K}};
Thread[m*x''[t] == A.x[t]]
{m x1"[t] == -K x1[t] + K x2[t],
m x2"[t] == K x1[ …
5
votes
Accepted
Identify maximum difference in Matrix
Depending on your taste,
d = MapThread[{#1[[1]] - #2[[1]], #1[[2]]} &, {X, Y}]
or
d = Transpose@{X[[All, 1]] - Y[[All, 1]], X[[All, 2]]}
define the differences d, if you need them. The symbol D …