Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions on the manipulation of matrices in Mathematica.

4
votes
2answers
50 views

How can I order this list on mathematica?

This is my list Matrix = {{1, -2, 3, -4}, {{a, b}, {f, e}, {a, b}, {f, e}}} I want to order the columns in ascending order depending on the values on the first ...
3
votes
2answers
50 views

Manipulation of 3D matrix

Assume that we have a 3D array x, and we would like to split it into 2D slices then cut every slice into some small patches and get all patches in single list ...
1
vote
1answer
45 views

Assume a variable is a Matrix

Is it possible to tell Mathematica to assume a variable is a matrix, analogous to assuming a variable is real with the Assuming command?
1
vote
1answer
24 views

How put a matrix in a row (with or without index titles) using mathematica

I am trying to put a 16x16 complex matrix in a row, with separated columns to real and imaginary parts (i.e a 1x512 matrix). Additionally this 16x16 matrix is generated by an operator ...
2
votes
2answers
54 views

Create a cross-section, time series data set using Matrix operations

I have developed the following code, which produces what I aim to obtain. ...
2
votes
1answer
68 views

Getting least norm solution

Noob question -- how should I get least norm solution in Mathematica for an under-constrained problem? Matrix is not full rank. I could use pseudo-inverse, but inverting a matrix to get a single ...
0
votes
0answers
22 views

Gradient of logdet(A+BXC) [on hold]

Let A,B,C are known matrices and F(X)=logdet(A+B.X.C). How to calculate the gradient of F(X)?
5
votes
6answers
336 views

Help with sum specific elements of a matrix in mathematica

I am trying to sum over specific indices in a matrix. For example, if I have the matrix a = {{1, 2, 3, 3}, {4, 5, 6, 6}, {7, 8, 9, 9}, {1, 5, 9, 7}} i need to ...
0
votes
1answer
50 views

How to replace a special arrow and row in a matrix with a symbol and drop it? [on hold]

I need to do a iteration, if condition[i] is true, I want to drop i row and i column in the matrix A. To keep the index of A unchanged, I think I should replace i row and i column as zero or other ...
0
votes
0answers
36 views

Cannot produce time series after matrix multiplication with Id or Diag matrix

I currently face the problem I cannot solve. I think the answer is obvious, but I am unable to solve it. When I do: ...
0
votes
0answers
24 views

Matrix equivalence over the integers

Is there any efficient way to tell whether two matrices $a,b$ are equivalent over the integers? That is, whether there exists some integer-valued matrix $c$ such that $$ a=c^Tbc,\qquad |\det(c)|=1 $$ ...
0
votes
1answer
77 views

How to generate a $ 9 \times 9 $ matrix like Sudoku ?

i want to generate a matrix that the number in each row, colum contains 1-9,and not repeated. my code always fall into no solution. here is my code. ...
4
votes
1answer
157 views

Multiplying list of matrices with vector of scalars

there are many similar threads on this forum, but none of them fixes my problem. I am trying to multiply List of Pauli Matrices with a vector of symbols (which are scalars). ...
2
votes
2answers
43 views

Convert List of Equations To Coefficient Matrix

I have the following list of 2 equations (but generally I have much more than 2 equations): m= {A1*x+B1*Sin[x]-C1*Cos[x],C2+A2*Cosh[x]} How could I ...
2
votes
2answers
48 views

How to return multiplicity of each eigenvalue?

I could not find the information so maybe someone know if it possible. I have a matrix which has several degenerated eigenvalues and I would like Mathematica to return the multiplicity of each ...
1
vote
2answers
45 views

Slider for a list of real numbers versus a list of matrices

Suppose that there are two lists, where capital letters in List1 denote matrices. ...
1
vote
0answers
18 views

Problem subtracting matrices [duplicate]

I am trying to study eigenvalues and eigenvectors using Mathematica. I am trying to compute $A-\lambda I$, so I created a matrix A and a matrix with $\lambda$ in the diagonal: ...
6
votes
2answers
253 views

how to construct a special matrix out of two lists

I have two lists as: abs = {a1, a2, a3, a4}; trs = {t1, t2, t3, t4}; I like to build the following special matrix: ...
2
votes
1answer
116 views

Mathematica won't multiply a numeric matrix by a symbolic matrix [duplicate]

If I1 = {{1,0},{1,-1}} and Acl = {{A , -B*K},{C*L, A-B*K-C*L}} where A, B, C, and D are not defined in the notebook. ...
3
votes
0answers
52 views

Antisymmetric Matrix Eigenvector Normalization

So, I have a complex $4n \times 4n$ antisymmetric matrix, $A$ and it has a non-degenerate spectrum. The matrix $A$ then has eigenvalues given by $$ \beta_{1}, -\beta_{1}, \beta_{2}, -\beta_{2}, ... , ...
0
votes
1answer
65 views

Working with Dirac Gamma Matrices using FeynCalc - A simple problem

I need to obtain this using package FeynCalc: $$ \begin{align} [\gamma_{0},\gamma_{i}]=& 2 \gamma_{0}\gamma_{i}, \\ [\gamma_{i},\gamma_{0}]=& 2 \gamma_{i}\gamma_{0} , \\ [\gamma_{0},\gamma_{...
0
votes
0answers
37 views

Defining commutations rules over arbitrary matrix

I'm working with spin connections with Dirac gamma matrix commutator (I know, mathematica has specific ways to work with it), and I need to define the following rules; $[\gamma_{0},\gamma_{i}]= 2 \...
4
votes
1answer
35 views

Check if a symbolic matrix is hermitian

I have a symbolic matrix: Potential = SparseArray[{Band[{1, 1}] -> V0/2, Band[{2, 1}] -> V0/4, Band[{1, 2}] -> V0/4}, {2*max + 1, 2*max + 1 }] ...
1
vote
1answer
34 views

How to choose elements of a matrix with internally generated variables and rank them with real coefficients

I have a Code (a long one), part of it is below. The following piece basically multiplies an adjacency matrix with a vector of equilibrium values. Then tries to pick non-zero elements to be used in ...
1
vote
1answer
32 views

How to collect eigenvectors corresponding to only positive eigenvalues?

Let us consider a matrix of order $n \times n$ with $n/2$ positive and $n/2$ negative eigenvalues. How to collect $n/2$ eigenvectors corresponding to positive eigenvalues in a matrix of order $n \...
0
votes
0answers
51 views

compiling matrix row assignment

I have this relatively simple code, generated with another Mathematica code (this is just an example): (edit: see below for simpler version) ...
2
votes
1answer
43 views

Matrix Randomization

Is there a way to take a 20x20 array and replace 2 random parts of this array with a 2x2 matrix? I've tried rvalues = ConstantArray[r, {20, 20}]; to make the ...
3
votes
0answers
97 views

Need to find matrix formulation [migrated]

I have a $B$ matrix: $B = B_{ij}$ I need to find closed matrix formulation of: $$\sum_i \sum_j \sum_m \sum_n B_{ij} B_{jm} B_{mn} B_{ni}$$ But I am so confused! Edit by Henrik: Originally, it ...
3
votes
3answers
106 views

Insert values into a Matrix under adjacency constraint

I created this matrix: latticeJ = ConstantArray[5, {20, 20}]; and I want to randomly replace 20 values of this matrix with the value of 10 under the condition ...
1
vote
3answers
95 views

Replace elements of a matrix with zeros using another matrix

I have a matrix Mat1 whos columns are ordered as : Col = Flatten[Outer[{#2, #1} &, {0, 1}, Delete[Range[-2, 2, 1], 3]], 1] ...
2
votes
2answers
49 views

Nested sorting of lists

I have the following list representing a custom set of cards: Each card is represented by a list of two elements, like this: {heart,9} Using the code: ...
0
votes
1answer
71 views

Sum of vectors to follow a path [closed]

I'm working with a mathematica program where I have a matrix with the xyz coordinates of the begin and the end of a group of vectors (randomly), here is the image: How can I sum two vectors where ...
3
votes
0answers
50 views

Arbitrary Precision, Nearly-Singular Matrices, and LinearSolve

I have been trying to solve a nonlinear eigenvalue problem, $\mathbf{M}(\lambda) \mathbf{v} = 0$, in Mathematica using Newton's method. The core of the algorithm relies upon an inverse iteration, ...
5
votes
1answer
70 views

Finding the orthogonal diagonalizing similarity of a symmetric matrix

I'm aware that there are some questions similar to this here, but none that could solve my problem. So, I have to diagonalize a symmetric symbolic matrix $m$ (to be seen below) and obtain the ...
2
votes
1answer
101 views

How to compute many sums or tables efficiently

I have some questions about programming in Mathematica and I would really appreciate it if you could help me. I wish to plot the following function against the variable X, but to do this, first I ...
4
votes
1answer
120 views

How to do $ \bigotimes_{i=1}^n A_i $ where $ A_i $ is a $ m \times m $ matrix?

$$ \bigotimes_{i=1}^n A_i $$ where $ A_i $ is a $ m \times m $ matrix. I want to do above operation, however KroneckerProduct in Mathematica must list all $ A_i $...
4
votes
1answer
139 views

multiply two vectors, component by component [closed]

Would like to take two vectors and multiply components at the same index.For example {a1, a2, a3} x {b1, b2, b3} to produce {a1 b1, a2 b2, a3 b3}. The following works, but are there some alternatives?...
2
votes
1answer
52 views

Taking a derivative of an eigenvector

I'm trying to calculate the derivative of an eigenvector that I obtain by ...
5
votes
1answer
76 views

How to plot complex eigenvalues of a matrix?

I have a matrix , for instance, like this : matrix[a_ ] := {{0, a}, {-a, 1}}; Eigenvalues[matrix[a]] and this give the eigenvalues that depends on ...
1
vote
2answers
79 views

How do I allocate an array of vectors? [closed]

I'm trying to follow the code posted by a user on Stack Exchange and I'm having trouble with an allocation of a matrix. The code is: ...
0
votes
0answers
20 views

Discrepancy in solutions given by Solve function

I wish to solve for the parameters g1 and/or g2 with which the eigenvalues of the following Matrix ...
-1
votes
1answer
30 views

column space having non-linear combinations of basis vectors [closed]

I have a matrix $A_{3x3}$ whose basis for the column space are $a_{1}=(2,2,5)$, $a_{2}=(9,5,3)$ and $a_{3}=(3,6,1)$. If these are the basis for the column space, then column space can always be ...
5
votes
0answers
75 views

Inconsistency in eigenvalues of matrices in a specific form (sparse & non-Hermitian)

Suppose one has a non-Hermitian sparse matrix defined as below ...
5
votes
1answer
87 views

Can a certain pair of expressions be compressed into one?

I've been employing this pair of statements ...
0
votes
0answers
30 views

Logarithmic solution of the matrix differential equation

I am looking for a solution of the matrix ODE $$\dot{\mathbf{x}}(t) = \mathbb{A} \,\mathbf{x}(t),$$ where $\mathbf{x}(t)$ is a vector and $\mathbb{A}$ is a matrix. I am curious if it is possible to ...
5
votes
2answers
106 views

Cumulative total of columns in a matrix or table

I have the following: matrix1 = {{a, b, c, d}, {e, f, g, h}, {i, j, k, l}, {m, n, o, p}} (Note that it's the data that matters, not the fact it's defined as a ...
3
votes
2answers
72 views
2
votes
1answer
41 views

Maximize with matrices

How do I use maximise with an arbitrary sized symbolic matrix? e.g for a small matrix it is fine to write it out, ...
1
vote
0answers
43 views

Find parameter which solves a 9-by-9 homogeneous system of linear equations, NSolve gives some incorrect answers

I have a set of 9 linear homogeneous simultaneous equations which depend on 2 parameters, p and x. For a chosen value of p, I aim to calculate the smallest 3 values of x which satisfy the simultaneous ...
0
votes
2answers
53 views

Why do I get a Partition::pdep error?

I've been running an iterative job (j=1,2.,3,.....300,000,000). The vast majority of steps proceed smoothly. Every several million or so steps, I get a "General::inf: Input matrix contains an infinite ...