Questions on the manipulation of matrices in Mathematica.

learn more… | top users | synonyms (1)

57
votes
7answers
11k views

Elegant operations on matrix rows and columns

Question The Mathematica tutorial has a section 'Basic Matrix Operations', describing operations like transpose, inverse and determinant. These operations all work on entire matrices. I am missing a ...
19
votes
4answers
2k views

Why does MatrixForm affect calculations?

This is a really newbie question, but it has me confused. Why does this code work without // MatrixForm and doesn't work with ...
24
votes
5answers
3k views

What is the most efficient way to add rows and columns to a matrix?

Say I have a matrix m and a vector v. ...
4
votes
4answers
7k views

Creating a table/Matrix during a For loop

I have a For loop (with i as a counter), which calculates different values (y1, ...
40
votes
6answers
3k views

Does Mathematica have advanced indexing?

I have two $M \times K$ arrays $L, T$ where I would like to set all the elements in $L$ to zero whenever the corresponding element of $T$ is greater than 15. The ...
5
votes
1answer
1k views

Mathematica won't give eigenvectors but Wolfram Alpha will? What am I doing wrong?

If I ask Mathematica to find the eigenvectors and eigenvalues of the matrix: ...
30
votes
6answers
1k views

How to visualize/edit a big matrix as a table?

Is it possible to visualize/edit a big matrix as a table ? I often end up exporting/copying big tables to Excel for seeing them, but I would prefer to stay in Mathematica and have a similar view as in ...
18
votes
3answers
2k views

How to symbolically do matrix “Block Inversion”?

Consider a block (partitioned) matrix matrix = ArrayFlatten[{{a, b}, {c, d}}] where, a, ...
1
vote
1answer
431 views

Contracting with Levi-Civita (totally antisymmetric) tensor

I have an array $v_{ijk}$ which is effectively a rank-$3$ tensor with dimensions $3\times3\times3$, and I need to contract it with $e^{ijk}$, i.e. evaluate $v_{ijk} e^{ijk}$ (see Einstein ...
20
votes
2answers
1k views

Cycles of length N in a graph

If I have an undirected graph represented with an adjacency matrix, how can I find all the subgraphs which are a cycle of length N? I don't really know the math nor the programming language well, so ...
35
votes
3answers
1k views

Tiling a square

I wondered if there was a way to automate the process of finding a way to tile a tile into a square. The idea is to represent the tile with a matrix of $0$s for blank space and $1$s for filled spaces ...
18
votes
2answers
3k views

How to enter matrices in block matrix format?

Example: I have a matrix $R = \left( \begin{array}{cc} A & \mathbf{t} \\ 0 & 1 \end{array} \right) $ where $A$ is 3-by-3 and $\mathbf{t}$ is 3 by 1. Or in Mathematica ...
4
votes
2answers
3k views

How to use a 3×3 covariance matrix to plot an error ellipsoid?

I have a 3×3 error covariance in Mathematica, but I don't know how to use it for plotting the error ellipsoid. It would be great if you can show me how I can do that for the below covariance matrix: ...
22
votes
2answers
333 views

eigenvector bug?

I have a fairly simple $3\times3$ complex matrix, $$ M=\left( \begin{array}{ccc} \frac{7}{2}-\frac{i}{2} & -1+i & \frac{1}{2}+\frac{5 i}{2} \\ -1+i & 5+i & -1+i \\ ...
8
votes
2answers
809 views

How to use “Drop” function to drop matrix' rows and columns in an arbitrary way?

The built-in function "Drop" can delete a Matrix's row and column. Typical syntax for "Drop" is as follows: Drop[list,seq1,seq2...] But what if I want to drop a ...
0
votes
3answers
642 views

Correct way to remove matrix columns?

I start off with m = 1000 x 5 matrix, and I would like to remove first column to get 1000 x 4 matrix and repeat again for ...
21
votes
2answers
2k views

How to form a block-diagonal Matrix from a list of matrices?

like this: I know join[...] works, but it is a bit troublesome for multiple matrices.I tried DiagonalMatrix[...], but DiagonalMatrix can only form matrix from a list of elements.
7
votes
4answers
470 views

Prepend 0 to sublists

My question is similar to this one, but my goal is to prepend a single 0 the each sublist, not incrementally many 0's. The file I'm working is a CSV containing around 50K sublists of length 35. I've ...
10
votes
3answers
2k views

Solving a time-dependent Schroedinger equation

I want to solve the time-dependent Schroedinger equation: $$ i\partial_t \psi(t) = H(t)\psi(t) $$ for matrix, time-dependent $H(t)$ and vector $\psi$. What is an efficient way of doing this so ...
15
votes
4answers
1k views

What is the right way to rotate an array?

Suppose I have an array, not necessarily square: a = $\left( \begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array} \right)$ I want to rotate it like one ...
10
votes
1answer
589 views

Nesting Parallel processes

I just attempted to run code that had nested ParallelMap[] functions. It generates the error message: ParallelMap::subpar: Parallel computations cannot be nested; proceeding with sequential ...
6
votes
3answers
687 views

How to manipulate gauge theory in Mathematica?

I want to know if there is a way of typing into Mathematica an expression like the following, $$\epsilon^{\mu \nu \lambda} f^{abc} A^a_\mu A^b_\nu A^c_\lambda + g\epsilon^{\mu \nu \lambda} A^a_\mu ...
10
votes
2answers
871 views

Non-commutative symbolic linear algebra

I am fairly new to Mathematica but I thought I would be a helpful tool to carry out a few simple linear algebra calculations. It seems like an easy task but I cannot figure out how to do it. For ...
13
votes
5answers
437 views

Graph from binary matrix (not adjacency) respecting the original matrix positions

I have a binary matrix. My objective is to connect every close (without "jump") elements with value equal to 1, but I must keep the point positions, just like it's shown at the image. Can somebody ...
12
votes
4answers
732 views

What is the fastest way to locate an image inside a larger image?

let b = let c = How to do: find[c,b] that returns the bounding box of c in b? ...
10
votes
3answers
915 views

Correcting a correlation matrix to be positive semidefinite

Does Mathematica have a way to "fix" a correlation matrix that is not positive semi-definite? I looked through the documentation and search the internet but could not find anything.
3
votes
4answers
341 views

How to transform this matrix & swap its columns in a simple way?

I would like to transform matrix $\mathbf A = \begin{pmatrix} a&b&i&j\\ c&d&k&l \\ e&f&m&n \\ g&h&o&p \end{pmatrix}$ into matrix $\mathbf B = ...
9
votes
2answers
2k views

How to get Matlab data imported with the same dimensions?

I have some Matlab image data with the following dimensions (output is from Matlab): >> size(im) ans = 86 86 3 45 The data imports just fine ...
4
votes
3answers
675 views

Minimum spanning Tree from a weighted adjacency graph

Note: Cross-posted at http://community.wolfram.com/groups/-/m/t/137658?p_p_auth=8QnKtT9I I have a really big graph, 40x40. Here is my code ...
14
votes
3answers
778 views

Constructing a symbolic Hermitian matrix

I need to construct a symbolic Hermitian matrix like m = { { n, a, b, b}, {Conjugate[a], n, b, b}, ... } but I am not able to set ...
12
votes
1answer
443 views

How to extract and replace submatrix of a doubly-periodic matrix?

How can I effectively extract and replace a rectangular subpart of a toroidal matrix, i.e. one where boundaries are connected at opposite ends? Since the submatrix can overhang the edges, a simple ...
11
votes
3answers
792 views

How can I visualize 6 square matrices as a cube?

I have six square matrices of the same dimensions in a list, for example: ...
4
votes
4answers
336 views

Listing matrices up to symmetry

I am interested in the equivalence relation on N x N binary matrices, in which two matrices are equivalent if one can be obtained by rotating/reflecting the other. I would like to obtain a list ...
4
votes
0answers
443 views

Analytically solve the eigenvalue problem with infinite dimensions by Mathematica?

If I am given a symbolic expression of all the matrix elements in an infinite-dimensional space, e.g., the Hamiltonian of a quantum mechanical system, is it possible to get the symbolic expression for ...
4
votes
2answers
455 views

All possible solutions to the Matrix Equation (free variables appearing)

I am attempting to solve a system of linear equations using LinearSolve[] . In my case, the number of unknowns are more than constraints. I learnt that LinearSolve ...
8
votes
3answers
793 views

Why don't * and ^ work as I expected on matrices?

For example, this input... {{1, 2}, {3, 4}}*{{1, 2}, {3, 4}} produces this output... {{1, 4}, {9, 16}} and this input... ...
7
votes
2answers
647 views

Entering block matrices for an arbitrary matrix size

Background: How to enter matrices in block matrix format? and the following: I want to create $$ f(A,t) = \left [ \begin{matrix} A & t \\ 0 & 1 \end{matrix} \right ] $$ where $A$ ...
5
votes
2answers
338 views

How to combine elements of two matrices?

Given two matrices m1 and m2, e.g.: m1 = {{a1, b1}, {c1, d1}} m2 = {{a2, b2}, {c2, d2}} How can one obtain the following? ...
3
votes
2answers
1k views

Matrix multiplication in Block Form symbolic calculation by Mathematica

I have a problem which requires taking product of two $10\times10$ matrices. I would like to do it by considering both matrices as $5\times5$ matrices such that each entry of both matrices is actually ...
2
votes
1answer
365 views

RowReduce: Solving for the resource vector (a, b, c) in Augmented Matrix

Here are two examples: RowReduce[{{3, 1, a}, {2, 1, b}}] evaluates to {{1, 0, a - b}, {0, 1, -2 a + 3 b}} but ...
0
votes
2answers
149 views

Taking averages at certain intervals

I am trying to take averages of a large two dimensional array at certain intervals. For example, for the first row, I want to take K averages of 500 values. Here is what I am trying ...
5
votes
1answer
128 views

Is it possible to lower the bitwidth of (floating point) numbers?

The answer to this question will most probably be a definite no. Nevertheless, I would like to know whether it is possible to represent reals in the memory on less than the standard 32 or 64 bits ...
5
votes
3answers
377 views

How to sum matrix elements based on finding the first (and second) non-zero elements of each row?

I have a matrix: I would like to sum all the first non-zero elements of each row so that I get a value of $$25.5317 + 8.85471 + 6.90018 + 32.9436 + ... $$ and so on and simply ignore zero rows. ...
2
votes
2answers
126 views

Matrix exponential via Cayley-Hamilton Theorem

I'm attempting to calculate the exponential of a matrix via Cayley-Hamilton theorem. (Following the "concrete example" from http://en.wikipedia.org/wiki/Cayley%E2%80%93Hamilton_theorem) I am having ...
2
votes
3answers
137 views

Join matrix based on conditions

Given the following matrix: ...
1
vote
1answer
203 views

General form of a linear transformation

Let $v_1 = \begin{bmatrix} 2 \\ -1 \end{bmatrix}$ and $v_2=\begin{bmatrix} 1 \\ -1 \end{bmatrix}$ and let $A= \begin{bmatrix} 3 & 2 \\ -2 & 1 \end{bmatrix}$ be a matrix for $T\colon \Bbb ...
0
votes
2answers
152 views

Eigenvector Anomaly

I'm trying to compute the eigenvectors for: $$ M = \left( \begin{array}{ccc} 1 & 4 \\ 4 & 100 \end{array} \right) $$ Both myself and Mathematica report the eigenvalues as: $$ \lambda_1 = ...
13
votes
1answer
389 views

Block Matrix Algebra with Mathematica

I have come up with some BlockMatrix Algebra for Mathematica to make notations easier. I have the following: ...
12
votes
4answers
407 views

How do you decompose a polynomial matrix into its matrix coefficients?

Let's say I have a matrix, $\mathbf{M}$, that is polynomially dependent on a single variable, such as M = {{15 + a^2, a + 5 a^2}, {a - 5 a^2, 2}} and I want to ...
8
votes
5answers
374 views

Is there a built in function to obtain the back diagonal of a matrix?

Given the following matrix: m = Array[Subscript[a, #, #2] &, {4, 4}] how can I find the skew diagonal or anti-diagonal or back diagonal of the matrix ...