Questions on the manipulation of matrices in Mathematica.
17
votes
4answers
797 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 ...
30
votes
6answers
4k 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 ...
18
votes
2answers
971 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 ...
16
votes
3answers
1k views
How to symbolically do matrix “Block Inversion”?
Consider a block (partitioned) matrix
matrix = ArrayFlatten[{{a, b}, {c, d}}]
where, a, ...
31
votes
6answers
2k 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 ...
28
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 ...
28
votes
2answers
603 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 0s for blank space and 1s for filled spaces ...
19
votes
5answers
1k 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.
...
14
votes
2answers
1k 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
1answer
461 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:
...
3
votes
4answers
3k views
Creating a table/Matrix during a For loop
I have a For loop (with i as a counter), which calculates different values (y1, ...
10
votes
1answer
368 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 ...
4
votes
2answers
628 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:
...
10
votes
2answers
572 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 ...
12
votes
4answers
513 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?
...
9
votes
3answers
525 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.
9
votes
2answers
959 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 ...
12
votes
1answer
262 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 ...
6
votes
2answers
389 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$ ...
4
votes
3answers
339 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 ...
5
votes
3answers
207 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.
...
4
votes
2answers
337 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...
...
9
votes
2answers
627 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 ...
12
votes
4answers
316 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 ...
14
votes
2answers
408 views
How to form a block-diagonal Matrix from a list of matrices? [duplicate]
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.
3
votes
4answers
237 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 = ...
15
votes
4answers
439 views
How do I generate the upper triangular indices from a list?
I have some list
{1,2,3}.
How do I generate nested pairs such that I get
{{1,2},{1,3},{2,3}}?
That is I'd like a way to ...
10
votes
5answers
946 views
Best way to create symmetric matrices
From time to time I need to generate symmetric matrices with relatively expensive cost of element evaluation. Most frequently these are Gram matrices where elements are $L_2$ dot products. Here are ...
4
votes
2answers
232 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 ...
4
votes
4answers
268 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 ...
14
votes
2answers
493 views
Using the Krylov method for Solve: Speeding up a SparseArray calculation
I'm trying to implement this Total Variation Regularized Numerical Differentiation (TVDiff) code in MMA (which I found through this SO answer): essentially I want to differentiate noisy data. The full ...
13
votes
3answers
458 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
4answers
283 views
Inputting a big structured matrix in Mathematica
Hi this is my first post and this is a problem that has bothered me a lot.
Suppose we have the $2012\times2012$ square matrix:
...
8
votes
2answers
196 views
Correct way to generate large data sets (i.e.forward yield curve )
I would like to generate a set of forward yield curve matrix of size 1000 x 100. First I defined my SparseArray of 1000 x100:
...
4
votes
2answers
150 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 ...
3
votes
1answer
400 views
stationary distribution of a transition matrix
How can I solve the stationary distribution of a finite Markov Chain? In other words, how can I estimate the eigenvectors of a transition matrix?
2
votes
3answers
623 views
7
votes
1answer
232 views
Efficiently Constructing Rank One Approximations for a Matrix using SVD
Suppose I have a $m\times n$ matrix $A$ (real for simplicity). Then SingularValueDecomposition[A] yields 3 matrices $U$, $\Sigma$ and $V$ such that
$A = U\Sigma ...
6
votes
0answers
227 views
MMA implementation of Earth Movers Distance?
Has anyone implemented in MMA the Earth Mover's Distance (EMD)? A concept dating back to Monge 1871, used to compare histograms and images, e.g., the CIEDE2000 Color Difference algorithm. Yossi ...
5
votes
2answers
185 views
Sort matrix by columns and rows without changing them
I would like to sort a matrix in descending order first by the total of each column, then by the total of each row, but without changing their content. For example, if I had:
...
5
votes
3answers
286 views
How do we solve Eight Queens variation using primes?
Using a $p_n $x $p_n$ matrix, how can we solve the Eight queens puzzle to find a prime in every row and column?
...
4
votes
4answers
961 views
How to convert equation to vector (matrix) form?
How can I convert expression a1*u1+a2*u2+a3*u3 to the vector form of dot product A.U, where ...
3
votes
2answers
237 views
Dynamic matrix multiplication
I have the following problem:
I want to multiply two matrices and sum them to another matrix C. A.B+ 2B Easy!
The matrix A varies as a function of three inputs a,b and c. The second matrix, B, is a ...
3
votes
2answers
278 views
Loop and do operations on Matrix, then graph the results
I'm trying to do some operations to a matrix in a loop, and then I want to graph the results.
The results are pair of numbers.
Can I store the results of each iteration on "something" and the use ...
3
votes
2answers
251 views
A dot appearing after a zero, and making the entries of a matrix into fractions
For more info about the difference between 0. and 0
I am a self-taught Mathematica user and I have some elementary questions-- perhaps too elementary for this site, but here they are.
If ...
2
votes
2answers
102 views
Optimizing functions taking matrix arguments
I'm looking for general information on how to optimize matrix valued functions, I have the following function I'm looking to maximize (or figure out if this is possible at all).
...
2
votes
3answers
275 views
2
votes
1answer
133 views
Numerical comparisons of matrices
I have a matrix which should be equal to a null matrix. However due to the numerical precision, a brutal equality test with a matrix initialized with zeros does not work.
How should I perform the ...
2
votes
2answers
557 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 ...
1
vote
2answers
183 views
Symbolically associate vectors and their norms
I am wondering how to handle the following situation: I do have vectors of known dimension that I would like to handle symbolically. I suppose I can do something like
...
