# Questions tagged [matrix]

Questions on the manipulation of matrices in Mathematica.

2,275 questions
Filter by
Sorted by
Tagged with
0answers
31 views

### To assign an array to a function

// Pre-defined parameter kS = 2*(\[Pi]*NefS)/LambdaSS; Here, NefS is a function of LambdaSS. The matrix m (i,j) defined corresponding value of NefS (jth ...
2answers
80 views

### How to calculate $(X^tX)^{-1}X^tY$? [duplicate]

This is MatrixForm[ {{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1.5, 1.5, 1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3, 3.2, 3.3}}] $X^t$ ...
0answers
35 views

2answers
51 views

### Simplifying complex-valued entries in a matrix

I have a matrix where some entries are complex or roots of unity. For example, (-1)^(2/9) - (-1)^(5/9) + (-1)^(8/9) is one such entry and it is equal to 0. ...
0answers
29 views

### How to represent Dirac matrices in general $n$ dimensions in mathematica? [duplicate]

I want to represent Dirac matrices in $N$ dimensions in Mathematica like we have for the Pauli matrices, i.e. PauliMatrix[i], {i,1,3} I guess there must be some ...
1answer
542 views

### 3.4 GHz Ryzen 5 slower to diagonalise large matrix than Intel i5-6300U 2.4 GHz

Sorry that this is quite a specific question but I need to diagonalise large matrices for the problem I'm trying to solve and can't for the life of me work out what's going on: I was expecting that ...
1answer
40 views

### How to extract a list from the table

What's and elegant way to extract List with components {x,y1} from the table with elements {x,{y1,y2,y3}?
0answers
32 views

### Selecting some vectors from a matrix

I am trying to write a code for band matrices that store only the nonzero vectors. For example if I have tridiagonal matrix of size 10, I want to store only the three diagonals as a vectors. n here ...
1answer
56 views

### Is it possible to solve for a matrix $m$ satisfying $m\cdot x=b$, given the vectors $x$ and $b$?

At first I thought it should be LinearSolve, which however turns out aiming at x, given m ...
0answers
63 views

1answer
143 views

### Numerically solving a system of ODEs where the functions are vectorized

I am attempting to solve a system of ODEs where a, b, cv1 and ...
1answer
38 views

### Why doesn't this Kronecker Product work with columns, but with rows?

Using the formula given in this math.stackexchange answer by the user greg \eqalign{ vec(M\otimes dK) &= \left(\pmatrix{I_T\otimes (M \cdot e_1)\cr I_T\otimes (M \cdot e_2)\cr \vdots \cr I_T \...
1answer
139 views

### Calculating the trace of the product of several matrices

I want to calculate the trace of something like $\qquad\mathrm{Tr}(\Gamma_RG_d\Gamma_LG_d^\dagger)$ In order to optimise my code, I found something like this Faster trace of product of two matrices, ...
1answer
43 views

### Selecting from a matrix according to elements of a column — efficiency and speed?

I need to select all elements from matrix M that have in their 3rd column elements from some given list L (3rd column and L are real numbers). I have written the most obvious (to me) command to select ...
4answers
783 views

### Set every element to zero in matrix unless it's 1 or 1/2

I have the following code: ...
2answers
158 views

### Display Short Form of Large Matrix

Is there a way to display matrices in a shorter form similar to Short or Shallow? I find that I very often want to inspect the ...
1answer
91 views

### Fastest, and numerically stable way to compute $CA^{-1}B$ and $CA^{-1}x$?

I have to compute $CA^{-1}B$ and $CA^{-1}x$, where $A,B,C$ are conformable matrices and $x$ is a vector. I'm not sure if it helps, but $A$ is symmetric and positive definite. The $A$ matrix will be ...
1answer
68 views

### What is going wrong when I try to solve a simple linear equation? [closed]

I'm trying to understand how does the LinearSolve function works. I'm trying it out like this: A' ...
2answers
99 views

### How can I compute the dot product of an arbitrary number of matrices?

First I make an example with three matrices. M = {{1, 2}, {3, 4}}; M = {{1.1, 2.1}, {3.1, 4.1}}; M = {{1.2, 2.2}, {3.2, 4.2}}; I want to calculate <...
1answer
76 views

### Problem with MousePosition after rotating a graphic

i've been doing a dynamic matrix plot using MousePosition but i need to rotate the plot 45°. but when i do that the MousePosition lose coordinates. Any idea of how to do the rotation keeping ...
2answers
189 views

### Catastrophic loss of accuracy in Orthogonalize

Context In connection to this question I am interested in orthogonalizing known matrices. As a test case, let us consider the definite positive $15 \times 15$ matrix ...
1answer
38 views

2answers
65 views

### How to show the whole table

I have this code ...
1answer
118 views

### Indices of nonzero rows in a sparse array

Given $A\!\in\!\mathbb{Z}^{m\times n}$ stored as a=SparseArray[{...},{m,n}], how can I obtain the list of all indices $i\!\in\!\{1,\ldots,m\}$ for which the $i$-th ...
1answer
151 views

### Delete zeros from a sparse array [duplicate]

Why doesn't SparseArray automatically remove zero entries? The code ...
1answer
90 views

### Why is part of the output “Null”? [closed]

Whenever I execute the code, portions of the output are null. How can I fix this? I am not sure the extent to which the result is invalid because I am not entirely familiar with the null output, ...
1answer
93 views

### Why does it say “objects of unequal length”?

This is my code: ...
1answer
404 views

### Change of basis in Mathematica

I'm trying to set up a change of basis matrix from the base V -> W with the RowReduce function that's built into Mathematica. I am then supposed to verify the result by taking the product of the ...
3answers
180 views

### How to collect eigenvectors corresponding to only real eigenvalues?

I have a set of eigenvalues which consists of real and imaginary values. Among these, I have one purely positive real eigenvalue and one purely negative real eigenvalue. How do I collect these two ...