Questions tagged [matrix]

Questions on the manipulation of matrices in Mathematica.

Filter by
Sorted by
Tagged with
2
votes
1answer
66 views

Numerical sum optimization

I need to compute the following sum as fast as possible: $$P_{ijkl}=\sum_{p,q,r,s}^nW_{sqpr}H_{js}G_{rl}A_{ipkq}$$ I came up with this code: ...
1
vote
1answer
84 views

Help in solve the matrix

I have written the following code. I have two main problems. The first is how to solve the matrix for different Omega, and the second is that if I put letters instead of numbers for k or m, the values ...
2
votes
4answers
76 views

Periodical sum of rows by a certain step

I've been struggling with one problem. I have a classic matrix in this example 12x4 such as: matrix = Table[i, {i, 12}, {4}] ...
2
votes
1answer
116 views

Creating adjacency matrix from another matrix

I'm trying to write a code which takes any $10\times10$ matrix as the input, assigns value of $i$ and $j$ to its elements based on their position in the matrix. Then using those values of $i$ and $j$ ...
3
votes
2answers
303 views

Matrix multiplication of non-commuting objects

I have two matrices, $A$ and $B$. The elements of these matrices are some abstract non-commuting objects, which I'm just representing as variables. For now, I don't care about having Mathematica know ...
1
vote
1answer
44 views

Getting message Set::setps: Kpr[x,y] in the part assignment is not a symbol

I use a loop to create a set of matrixes Subscript[k[x, y], i], depending on variables x, y. Then I create a large matrix ...
6
votes
2answers
258 views

Check if rows and columns of matrices have more than one non-zero element?

I am given a list of square matrices (with non numeric entries but abstract symbols which are assumed to take real values) and I want to write a function that returns True if the following condition ...
5
votes
1answer
51 views

Adding lists to specific elements in a list

I have compiled lists of non-diagonal and diagonal entries for a matrix. I'm trying to add elements from the diagonal-entry lists into certain entries of the non-diagonal lists. Is there a feasible ...
2
votes
1answer
55 views

Why the “Sum” function becomes extremely slow at a specific size of matrix? How to AVOID it? [duplicate]

Three methods("Sum", "Total@Table" and "Do") have been used to do the same work. The "Sum" and "Total@Table" function becomes extremely slow at num=...
0
votes
0answers
32 views

Manipulation of a symbolic matrix expression

I have the following code: ...
1
vote
0answers
32 views

How to speed up this code (finding eigenvector with smallest eigenvalue)? [closed]

I have following code. The function TraceSystem is to take partial trace of matrix and I think this part is fine. The main code is below in dd and I think the main problem is in here for Eigenvector. ...
0
votes
0answers
25 views

Solving quadratic eigenvalue problem [duplicate]

I am trying to solve a quadratic eigenvalue problem using Mathematica similar to Matlab command "polyeig" https://www.mathworks.com/help/matlab/ref/polyeig.html How to do it using ...
2
votes
0answers
74 views

What is the fastest way to get the lowest eigenvalue and corresponding eigenstate in Mathematica?

I tried to use the Arnoldi method to get the smallest eigenvalue and corresponding eigenstate for large matrix. However, Arnoldi did not give me the desired result: ...
2
votes
1answer
35 views

How to change an element in matrix, based on equality of other elements?

I have following problem. I can solve it without any real troubles using 2 for cycles. Knowing it is not really a Mathematica friendly approach, can you give me suggestions of a nice Mathematica code? ...
0
votes
1answer
32 views

Function isn't adding the 2 matrix [closed]

Having an issue where my function rotMatfromVec won't add the 2 Matrices at the end. It takes in 2 inputs, R and theta, where R is a unit vector. ...
-2
votes
1answer
52 views

Sorting of eigensystem accroding to specific eigenvector

I have a matrix, I want to sort it with respect to specific eigenvectors. Here, I provided an example of a matrix HT: ...
0
votes
1answer
89 views

Having problem in evaluating the eigenvalues of an $11\times11$ symmetric matrix in Mathematica [closed]

I am solving an $11\times11$ matrix in Mathematica. I am facing problem when I try to find the determinant or eigenvalues of this matrix. The error (Det::matsq/<...
0
votes
0answers
51 views

How To Define An Outer Product (in xAct)?

I am working with xAct / xCoba / xTras and I would like to construct a matrix out of a vector. So, I have a vector V on a manifold ...
0
votes
1answer
77 views

Matrix as the discretization of a function $u$ over a rectangle in 3D, how to integrate fast along the axes

I have a function $u$ from 3D to 1D approximated in a list uu and I want to calculate e.g. $$\int_0^1 x\cdot u(x,y,z)dx$$ or $$\int_0^1\int_0^1\int_0^1 u(x,y,z)...
0
votes
1answer
52 views

Testing a condition to replace elements of amatrix [closed]

I want to write a code that checks each element of a given matrix C2 and in case they are't 0 or 1 , replaces them with 1. My code is so far as follows and the code ...
3
votes
2answers
126 views

How to efficiently check if a matrix is a Toeplitz Matrix

With ToeplitzMatrix we can create a Toeplitz matrix from a list of values. I have a question going in the opposite direction, namely, how to efficiently check if a ...
4
votes
4answers
129 views

Double contraction between 2nd and 4th rank tensor

I would like to compute the double dot product between a 2nd and 4th rank tensor in mathematica $A_{kl}A_{ijkl}$ $if \, A_{kl}=\begin{pmatrix} 1& 0 & 0\\ 0 & 1 & 0\\ 0&0 & 1 \...
2
votes
1answer
85 views

Plot the indices of the background Matrix instead of the calculated values

I want to create a background 60*100 matrix and insert inside it the calculated values, for example ...
0
votes
0answers
47 views

Simplifying elements of a matrix

These elements of the matrices can be simplified by hand much further{roots can be cancelled and all}, yet the Fullsimplify in Mathematica doesn't simply it completely. The matrix is: ...
0
votes
1answer
58 views

Need help reviewing Mathematica expression which came from Physics

Please help me check the conversion of these two expressions in physics to their respective Mathematica expression. Where sigma is the Pauli matrices in standard form, E/p0 is energy, m is mass and p ...
2
votes
0answers
56 views

Referring to matrices with index [closed]

For exampe I have two matrices, with index 1 and 2 Mat[1] = ConstantArray[0, {2, 2}] Mat[2] = ConstantArray[0, {2, 2}] I wanna assign new value with ...
4
votes
2answers
185 views
6
votes
1answer
104 views

Efficient construction of a SparseArray from LIL (list of lists of column entries)

In Python scipy.sparse, there are methods to convert between CSR, CSC, LIL, DOK, etc. implementations of a sparse matrix. What is the most efficient way in Mathematica to construct a ...
0
votes
0answers
49 views

How to work with a function in vector form

I would like to use Mathematica to compute the X and Y elements of the vector on the left (below) for various t values and put result in a column vector form? I used Mathematica's palette to write the ...
0
votes
0answers
31 views

Direct production between two arrays must have an array shape

I wish to have a result such as: {0,1,0,0} after producing two vectors: v1={1,0} and v2={0,1}...
5
votes
6answers
559 views

Representation a matrix as a colored square shape

I am sure that I have accidentaly seen before a way to construct a square shape corresponding to a matrix. For example if we have a 5*5 matrix: ...
7
votes
2answers
544 views

How do I invert my matrix?

I have the following matrix $M$: \begin{bmatrix} P & p & 0 & 0 \\ pe_1 & Pe_1 & \sqrt{P^2 - p^2}q_1 & \sqrt{P^2 - p^2}r_1 \\ pe_2 & Pe_2 & \sqrt{P^2 - p^2}q_2 & \...
0
votes
0answers
20 views

Assumptions with piecewise problem?

I am trying to apply the assumpion of 0<s<1 throughout the calculation however the piecewise condition does not accept it automatically. Is there any way to avoid the manual choice of x>0. ...
2
votes
0answers
32 views

Setting pieces of “matrices” - unwanted behavior

I am constructing matrices whose elements are lists themselves (of varying length), and am (re)setting the entries of these matrices using among others the "All" command. It seems that in ...
0
votes
1answer
44 views

Mathematica not computing Matrix problem, just returning multiplication expression [closed]

I'm doing some very simple matrix operations in Mathematica, but for some reason, the last operation I'm trying to evaluate is not returning the actual product, just shows the symbolic multiplication. ...
1
vote
1answer
81 views

How to compute k'th tensor power of matrix

Is there a 1-liner to compute $M^{\otimes k}$ where $M$ is some matrix and $\otimes$ is the Kronecker product? The documentation says I can write ...
0
votes
1answer
39 views

Algebraic simplification of elements in a matrix

The matrix is defined as: ...
1
vote
1answer
34 views

Is there a more natural way to create matrix from consituitve blocks?

I have a matrix that I'd like to augment with identity: ...
0
votes
3answers
137 views

How to make conjugate transpose of this matrix?

The 4x1 matrix is defined as: ...
1
vote
0answers
63 views

Problematic matrix calculation [closed]

I have defined matrix as such u1 = {0, I, 0, 1}; u2 = {I, 0, 1, 0}; λ1 = Sqrt[m/2] (u1 + (I*u2)); Now I define the matrix multiplication with $ 4\times 4 $ matrix ...
3
votes
5answers
481 views

How to create a matrix with n*n dimensions which is not an exact number? [duplicate]

I want to get a matrix like this: It has n*n dimensions but n is not an exact number. I have tried some functions like Table and Matrix, but they did not work while n was a symbol. ...
1
vote
2answers
61 views

How to make a matrix of multivariable functions?

It might be a very basic question! Let say that I have an array of variables as the following x = {{x11, x12, x13, x14}, {x21, x22, x23, x24}, {x31, x32, x33, x34}, {x41, x42, x43, x44}, {x51, x52, ...
0
votes
3answers
90 views

Solve for matrix in linear equation

I need to find a matrix M such that M.u = v, where u and ...
2
votes
2answers
127 views

Solving Simultaneous equations of matrices

I am in a precarious situation where I have two equations: eq1 = α1 + αt12.t1 + αr11.r1 == 0; eq2 = γ1 + γt12.t1 + γr11.r1 == 0; Where each variable is a 3x3 ...
0
votes
1answer
42 views

A four-by-four matrix as a function of $ \omega $, but its determinant is scalar [closed]

I have four equations that I have written in matrix form. The matrix is a function of $ \omega $. But When I extract the determinant of the matrix it turned out to be a scalar value. What is the ...
3
votes
2answers
223 views

Creating of the Jordan Canonical Form

I have a matrix polynomial P(s) and the Jordan blocks of P(s) corresponding to every eigenvalue sj (j=1,...,k). How can the Jordan Canonical Form be generated, i.e. the block diagonal matrix which has ...
0
votes
0answers
38 views

Problem in getting the full rank of a matrix

I have 17 equations I am trying to put them in the matrix form. I am trying to understand why the matrix is not full rank. ...
0
votes
1answer
58 views

How to combine MatrixPlot with ListPlot

I want to combine a ListPlot with a MatrixPlot. I have a set of points to be used with a ListPlot. At the same time, I want to show a kind of heat map to show the intensity of their locations in a ...
1
vote
4answers
118 views

Creating a block diagonal matrix when the submatrices in the diagonal are unknown

Let us assume that we have an integer $j$ $(j=1,2,...,k)$ and that for every $j$ is generated a matrix $P$ of dimensions $j$x$j$ . For example, if $j=1$ then $P=(-2)$. If $j=2$ then $$R = \begin{...
0
votes
0answers
35 views

Large difference in the time it takes to compute the transpose of a matrix

This is a simplified version of the program I'm working on. I'm working with some large vectors that I have to transpose at the end in order to get the result I'm looking for. I have two versions of ...

1
3 4
5
6 7
59