Questions tagged [matrix]
Questions on the manipulation of matrices in Mathematica.
3,488
questions
1
vote
0
answers
90
views
How to optimally defragment the colors? [closed]
This is a matrix plot with randomly selected colors. I like to defragment the colors to create an optimal grouping of cells with the same color.
...
5
votes
2
answers
100
views
Finding a basis of positive vectors in the kernel of a matrix
The kernel to the left of the matrix
...
4
votes
1
answer
151
views
How to plot the elements of a matrix in {x,y,z} coordinates?
I have the {x,y,z} positions of a fullerene and after connecting the first neighbors with ~1.37 and 1.45 distances in the matrix B as the following
...
0
votes
0
answers
78
views
The multiplication result is not written as a number [closed]
This is my code:
...
1
vote
2
answers
98
views
How to construct a custom-made matrix conditional on a set of rules?
The following code does what I intend to achieve; however, it is too cluttered for a simple matrix operation. I like to reduce the code to a one-line code as a ...
0
votes
0
answers
40
views
Matrix Dimension Changes [closed]
I am trying to run the following code:
...
0
votes
1
answer
42
views
'The objective function is not a scalar' in NMinimize
I am trying to do a GMM(Generalized Method of Moments) by NMinimize, it comes up with the warning 'The objective function is not a scalar', here's what I have tried:...
12
votes
6
answers
2k
views
2
votes
3
answers
78
views
Convert a string with $N^2$ entries to a rank-$N$ matrix
Suppose we are given a set of numeral data like a string that consists of $N^2$ entries, say $N$ is very large (here $N=8$ for simplicity, but $N$ can be $10^8$...)
...
0
votes
0
answers
78
views
Output a 24 by 24 Leech lattice
Input a rank-8 $E_8$ lattice,
$$
M_{E_8}=\begin{pmatrix}
2 & -1 & 0 & 0 & 0 & 0 & 0 & 0 \\
-1 & 2 & -1& 0 & 0 & 0 & 0 & 0 \\
0 &...
0
votes
1
answer
89
views
Symbolic matrices
How does one declare a matrix of specific symbolic dimension? For instance, if $A,B,C,D$ are four $n\times n$ matrices, $M$ is the block matrix
$$
M=\begin{bmatrix}
A & B \\ C & D
\end{bmatrix}...
2
votes
0
answers
65
views
Giving MatrixPlot coordinates [closed]
I am using MatrixPlot for plotting the following array
...
7
votes
4
answers
505
views
Fill an empty matrix with the depth of its elements
Given an arbitrarily nested empty matrix like for example
mat =
{
{},
{{}, {}},
{{}, {{}}, {}},
{{}, {{}}, {}, {{{}}}}
};
and knowing that
...
2
votes
0
answers
66
views
Performance of multiplying two identity matrices
I am running Mathematica 13.3.1.0 on a M1 Mac, and I ran the following codes to check on the time spent on matrix multiplication.
...
3
votes
4
answers
365
views
Eigenvectors are divided by zero depending on evaluation, 6x6 matrix
I calculated the Eigenvectors of the $6\times 6$ matrix $m$ with parameters $(a,b,c,d,e,f)\in \mathbb{R_{\ge 0}}$. If I set e.g. $b\rightarrow 0$ after calculation, then 4 of the 6 Eigenvectors are ...
4
votes
3
answers
434
views
Eigenvectors are divided by zero depending on evaluation, 4x4 matrix
I calculated the Eigenvectors of the $4\times 4$ matrix $m$ with parameters $(a,b,c,d)\in \mathbb{R_{\ge 0}}$. If I set e.g. $b\rightarrow 0$ after calculation, then some of the Eigenvectors are ...
1
vote
2
answers
109
views
How to plot a matrix with this 3D style in a bar chart?
Reading the paper Measuring Wigner functions of quantum states of light in the undergraduate laboratory in arXiv, I found the figure above, whose style is very beautiful. I tried to reproduce it, but ...
2
votes
1
answer
89
views
Solving a Lindblad differential equation in matrix form
I am trying to solve the following Lindblad equation analytically with Mathematica:
$$\frac{d\rho}{dt}=-i[H,\rho]+\sum\nolimits_{i=0}^1 K_i\rho K_i^+-\frac12\cdot\{K_i^+K_i,\rho\},$$
where
$$H=\begin{...
0
votes
0
answers
28
views
Sparse Kronecker Product of Pauli Matricies
Suppose I have a list of Pauli matrices (X, Z and I type)
paulis = {x,z,z,i,z,x,i,z};
I would like to compute a sparse array equivalent to
$$x \otimes z\otimes z \...
1
vote
3
answers
192
views
How to implement tridiagonal matrix algorithm?
I have created the tridiagonal matrix below:
...
0
votes
0
answers
59
views
Plotting list of points to a special graph
Given Mathematica code of eigenvalues in different variable-paths , I want to add experimental data in the path Gamma-X ; X-Gamma ; and M-Gamma .
Here is the code :
...
0
votes
0
answers
29
views
How to extract subscripts in mathematica and apply a function on them?
For a bit of context, I am trying to evaluate an integration over Haar randm unitaries. I couldn't find any inbuilt function, so I am trying to implement a simple code for the Wingarten functtion in ...
0
votes
1
answer
81
views
Eigenvalue Problem - Nullspace Basis
I need to solve an eigenvalue problem where some of the eigenvalues are 0. Due to the fact that I just need the eigenvectors associated to the 0-eigenvalues in some cases I'd just like to calculate ...
6
votes
4
answers
650
views
Find a certain path through a matrix
I would like to get a functional solution and nice display form for the following problem:
1. Example data
...
1
vote
1
answer
83
views
How to calculate maximum between two or more lists element by element and also the index corresponding to the maximum element?
I am looking for a function say f such that for example
f[{a1,b1,c1},{a2,b2,c2}] will give {Max[a1,a2],Max[b1,b2],Max[c1,c2]}
and also a function g say such that
g[{{a1, a2, a3}, {b1, b2, b3}},{{c1, ...
2
votes
1
answer
66
views
Efficient ways to generate a matrix from multiplying two elements of some matrix
I am working on the single particle entanglement entropy and in the process I have something like
...
0
votes
0
answers
91
views
Solve does not find solutions to large equation rotation matrix
I've been seeing some posts already where people mention Solve needs a bit of help to get things solved in some scenarios.
I have been trying to figure out the solutions for equations. For the XYZ ...
1
vote
1
answer
123
views
Using "Table[]" to create a matrix without submatrices [duplicate]
I'm trying to create a certain 6x6 matrix using Mathematica's in-built "Table[]" function and have landed on
...
5
votes
4
answers
112
views
Interpolation of missing matrix values
Problem statement
I want to replace missing matrix values, denoted by an integer 0, with the Mean of their surrounding values.
...
7
votes
8
answers
785
views
How can I expand a matrix and fill in zeros?
Given a square matrix like
m = {{1,2,3},{4,5,6},{7,8,9}};
I want to expand it to a 5x5 matrix
...
2
votes
0
answers
67
views
Elegant operations on associations and datasets
As a useful extension of this question:
Elegant operations on matrix rows and columns
I would like to ask:
What are for you elegant, short, useful or frequently used functions to use with ...
2
votes
1
answer
113
views
Simple subtraction of two square matrices giving strange results [closed]
I'm new to Mathematica, and I'm writing a function to calculate a complicated pdf. I'm having trouble doing something very basic, subtracting one square matrix from another. I've reduced my problem to ...
0
votes
0
answers
43
views
On MacOs, I cannot use Needs["QDENSITY`Qdensity`"]
I am trying to get
Needs["QDENSITY`Qdensity`"]
from (https://library.wolfram.com/infocenter/MathSource/5715/), however, it failed and I get this error:
...
0
votes
1
answer
85
views
How to incorporate boundary conditions?
I have this linearized PDE problem:
$$\lambda a^\ast+\bar{a}v^\ast_z+\bar{a}_zv^\ast+\bar{v}a^\ast_z+\bar{v}_za^\ast=0$$
$$\lambda \bar a h^\ast -\bar a \bar h v^\ast_z-\bar a \bar v_z h^\ast - \bar h ...
-1
votes
1
answer
59
views
Make a table in matrix form to display the values of x and y if y =sin[x] and x takes on the certain values [closed]
Don't understand how to do this, tried plugging in "if" statements but my commands won't go through.
Extremely new to Mathmatica
0
votes
0
answers
45
views
Matrix subtraction not working [duplicate]
I am using Mathematica to solve a hw question.
I have the following code:
...
1
vote
4
answers
302
views
How to observe transition pathway of a stochastic matrix?
Given a stochastic matrix, m, I like to observe the transition path converging to the limiting distribution.
...
3
votes
4
answers
447
views
Find the shortest possible unique keys
1. Problem statement
Given a certain rectangular matrix I want to scan its rows from left right to find equally sized sequences. These sequences should be as short as possible and unique, so that they ...
5
votes
4
answers
320
views
Show positions of duplicated matrix elements
1. Problem statement
I want to replace duplicated elements within a matrix with a placeholder value.
2. Example data
...
3
votes
0
answers
76
views
Mathematica's definition of cos(kA) where A is the 1st Pauli spin matrix [closed]
For a homework assignment I was asked to derive the formula of $e^{ik\sigma_{1}}$ - where $\sigma_{1}$ is the Pauli spin matrix {{0,1},{1,0}} - using the Taylor ...
3
votes
2
answers
189
views
Sort sequences by their "randomness"
Example matrix (rows always have equal lengths)
...
1
vote
0
answers
86
views
Using Mathematica to find the eigenvectors
I would like some clarification about solving for eigenvectors in Mathematica.
I am looking at the following matrix:
\begin{equation*}
L =
\begin{pmatrix}
0 & m(1+\frac{kmwr}{\lambda}) \\
q(1-kpx)...
1
vote
0
answers
69
views
Solving a linear algebra problem containing minimal polynomial degree
Consider a set of three-dimensional points ${\left\{{\left(a,ab,abc\right)}~\middle\vert~a,b,c\in\mathbb{N_+}\land a+b+c\leqslant2023\right\}}$. If there exists a non-zero real polynomial $\...
0
votes
0
answers
60
views
Don't understand reasons for error messages when trying to get elements of matrix
I am trying to simplify the seemingly very complicated inverse of a 4x4 matrix. "Simplify" resulted in something only somewhat less complicated. So yesterday I started simplifying the ...
0
votes
0
answers
37
views
Root function in the output [duplicate]
I was calculating the eigenvalues of a matrix and the output contained some eigenvalues like:
...
1
vote
1
answer
152
views
How can I get the determinant of an 8x8 matrix in a particular form?
I would like to get the determinant of a 8x8 matrix with symbolic representation to a particular form. When I used determinant and fullsimply to answer was too long and did not match the form I was ...
0
votes
0
answers
72
views
How do we convert the minimum of two values into its actual result?
I am writing a code in Mathematica where the entries of the matrix depends on the minimum function, which is a function of the position in the matrix. However, when I compile it, the entries appear as ...
1
vote
2
answers
89
views
Solve a non-trivial matrix equation for an unknown matrix
I am solving the matrix equation to pass from the Fokker-Planck to the Langevin equation. Specifically:
\begin{equation} D=BB^T
\end{equation}
where
$$ D=
\left(\begin{matrix} l x_1(1-r_1) + e_1 r_1 ...
4
votes
1
answer
70
views
Commutant of set of matrices
I'm trying to compute the commutant of a set of matrices, so the set of matrices that commutes with all matrices in the original set.
I'm a complete newbie with mathematica, so I would be greatful for ...
1
vote
1
answer
156
views
Gauss elimination with pivoting error
I am attempting to write code for Gaussian elimination with pivoting. I need my code to be able to find the maximum pivot in the column and swap the rows to ensure that the first element is always the ...