Questions on the manipulation of matrices in Mathematica.

learn more… | top users | synonyms (1)

7
votes
2answers
354 views

Finding a unitary matrix in Mathematica

I have the following equation : $ \tilde{B} = U B U^{\dagger} $ I also know both $ B $ and $ \tilde{B} $ , I just want to find the matrix U, that gives me the transformation. I tried using ...
18
votes
1answer
457 views

Sparse Cholesky Decomposition

I am working with square matrices with a special form, which for large rank ($> 100,000$) would be best stored and manipulated as a SparseArray. I believe that ...
6
votes
3answers
236 views

How to create a general format of a matrix with specified entries?

I want to create a PNG picture of a matrix where its entries are the following: ...
1
vote
2answers
54 views

Bin data from an imported excel file by adding 5 elemets of y axis each [closed]

So i imported a file from excel and viewed it as a grid. but now i need to add groups of 5 elements from the y axis and plot them against every fifth entry from the x axis. Thanks Edit: Sorry about ...
1
vote
0answers
125 views

Speed matrix multiplications

I am trying to run this function ...
10
votes
3answers
470 views

How do you concatenate matrices? And how do you make block matrices?

This is pretty trivial to do in Matlab, but I have not seen a function for it in Mathematica. Here is how you can do it with Join and ...
2
votes
1answer
159 views

Eigenvectors of numerical matrix

I have a large numerical matrix whose eigenvalues are all distinct. In the documentation for Eigenvectors it says: For approximate numerical matrices m, the ...
1
vote
0answers
46 views

matrix multiplication performance

I would like to evaluate $$ f(x,y)=\sum_{i=1}^{N} X_i(x)\,Y_i(y) $$ where $X_i(x)$ and $Y_i(y)$ are known functions for all $i=1,\ldots,N$, and $x$ and $y$ are from the rectangle $[0,A]\times[0,B]$, ...
0
votes
0answers
116 views

LU factorization

Basically what I need to do is this: Write an algorithm that finds the LU factorization of the following matrix. The algorithm should perform the necessary elementary row operations to reduce A to U, ...
3
votes
1answer
34 views

Difficulty with LevelSpec. Product of empty set should be 1

I have a matrix newm = {{{}, {}, {-p}}, {{d}, {e}, {p}}, {{g}, {h}, {i}}}; MatrixForm[newm}; whose elements are lists. I would like to multiply the elements of ...
2
votes
3answers
64 views
9
votes
7answers
264 views

Custom Matrix product

I have a list: list1 = {{{a1, a2, a3}, {b1, b2, b3}}, {{c1, c2, c3}, {d1, d2, d3}}}; I want an operation that gives me: Is there a built-in way of doing ...
4
votes
1answer
203 views

What is the Mathematica equivalent for corr2?

What is the Mathematica equivalent for MATLAB's corr2, which gives the correlation coefficient of two 2D matrices?
1
vote
2answers
124 views

Row-wise matrix multiplication

I have a matrix $A=\{a_{ij}\}$ of dimensions $n$ rows by $m$ columns, and I would like to multiply each row of the matrix by a constant $b_i$, $i=1,\ldots,n$, and store the result in the same ...
2
votes
2answers
768 views

Determinant of a large matrix and solution of a linear equation

I am trying to solve a linear equation in x, where the equation is given by Det[M]==0. The M is a symmetric matrix (dimensions 47x47) with an element equal to x and all other elements are equal to ...
1
vote
0answers
48 views

Sampling from an one-dimensional Wishart [closed]

I searched for a similar question but could not find one. My problem is sampling from an one-dimensional Wishart distribution. The Mathematica specification is ...
4
votes
1answer
114 views

Is it possible to find the vectors that span the nullspace of a large, symbolic matrix

My problem is composed of two parts, a large sparse matrix $L$ ($m$x$n$ where $m=10^3$, and $n=10^5$, with $10^7$ non-zero complex numbers), and a dense, symbolic matrix $F$ ($m$x$m$ where $m=10^3$), ...
9
votes
1answer
670 views

Symbolic scalar-by-matrix derivative

Let's say I want to calculate the following scalar-by-matrix derivative $$\frac{\partial}{\partial A} \text{tr} \left[(\vec X^T A)^T (\vec X^T A)\right],$$ with $\vec X$ and $A$ being a $n \times 1$ ...
5
votes
1answer
120 views

How to do matrix calculus in Mathematica?

I would like to differentiate Ax with respect to A where A is a matrix. Now, obviously, I know the derivative is x but for more nasty expressions, is there a way to differentiate expressions with ...
6
votes
1answer
100 views

Speed up the auxiliary function magicSquare when $n$ is doubly-even

Today, I saw a question about magic square (please see here). When $n$ is doubly-even, namely for Mod[n,4]==0 ...
1
vote
1answer
97 views

Converting the subscript of matrix name to a variable

I want to change indices of matrix name during loop for creating different matrices. For example; ...
0
votes
2answers
84 views
20
votes
2answers
777 views

Obtain approximate Hessian using FindMinimum

According to the documentation, when FindMinimum is told to use the method "QuasiNewton" on a unconstrained problem, it uses the ...
6
votes
1answer
517 views

Is there any faster way than Eigensystem to diagonalize a Hermitian matrix?

Is there any faster way than using Eigensystem to diagonalize (get all the eigenvectors and eigenvalues) of a Hermitian (self-adjoint) matrix? That would be ...
19
votes
11answers
1k views

Efficient way to build a certain square matrix

For odd n I'm looking for a short and swift way to construct with (f.e.) n = 3 n = 11 ...
11
votes
1answer
408 views

Is it possible to implement symbolic sub matrices?

The accepted answer in the question Symbolic matrices in Mathematica with unknown dimensions provides a functionality to create symbolic matrices which behave pretty much as the name suggests. ...
17
votes
1answer
304 views

Simple Matrix multiplication takes very long

Bug introduced in 10.1.0 and fixed in 10.3.0 I came across some strange behaviour during a computation involving matrices with symbolic values. It is reproduced below. Multiplying a random 30x30 ...
7
votes
3answers
324 views

Can't find the eigenvectors of a simple 2x2 matrix

Bug introduced in 8.0 or earlier and fixed in 10.3.0 Why can't Mathematica find the eigenvectors of this matrix? ...
2
votes
3answers
260 views

Eigenvalues of a large matrix

I want to compute the eigenvalues (and later the corresponding eigenvectors) of an $n\times n$ Hermitian matrix. For this I use {evs, vecs} = Eigensystem[matrix] or ...
6
votes
0answers
74 views

How to instruct MatrixLog to work with singular matrices?

How to instruct MatrixLog to work with singular matrices by ignoring the zero eigenvalues (thus only acting on a subspace orthogonal to the matrix kernel)? I'm ...
14
votes
6answers
1k views

Generating an Ulam spiral

An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one ...
3
votes
2answers
131 views

Given a list of positions in a matrix, get elements within radius r

I have a n x n binary matrix like SeedRandom[1]; mat = RandomInteger[1, {9, 9}]; MatrixForm[mat] I want to create ...
5
votes
1answer
114 views

Evaluating only one column of a $m \times m$ matrix without evaluating the matrix itself

Suppose I have f[x_] := SparseArray[{someRules}, {m, m}]; g[x_] := MatrixPower[f[x], k]; Would it be possible to evaluate only the $n$-th column ($n\neq m$) of ...
6
votes
2answers
162 views

Grouping the list of numbers that have common.

I am working on some simple problem. It is like puzzle.. Let's say I have some list input={{1,1},{1,2},{1,3},{2,3},{3,3},{4,4}} Which means 1 can go and back to ...
2
votes
3answers
64 views

Having a function check a column and perform a task every time an entry satisfies a condition

So I have a matrix (technically a table) points = Table[{x, f[x]}, {x, Range[0, 2, .1]}]; Which gives something like this in matrixform \begin{array}{cc} ...
7
votes
0answers
126 views

Examples of using Mathematica to solve matrix equations symbolically

Suppose we want to solve a linear system like $$\left\lbrack\begin{array}{cc}M& S\\ -S^\mathrm{T}&0 \end{array} \right\rbrack \left\lbrack \begin{array}{c} x\\y\end{array}\right\rbrack = ...
1
vote
2answers
142 views

Partitioned matrix operations

I have a $(2 \times 2)$ matrix whose elements are themselves $(2 \times 2)$ matrices (i.e., a partitioned matrix), e.g: $$ M = \begin{pmatrix} A & B \\ C & D \end{pmatrix}, \quad \quad ...
2
votes
1answer
79 views

Merge two matrices where one may be empty

In a loop, I want to merge two matrices A and B where B is sometime empty. Example: ...
3
votes
1answer
69 views

Large products of a matrix-valued function [closed]

I have a $3\times 3$ matrix valued function $f(x)$ where $x\in\mathbb{R}$. I want to perform the following: $$\prod_{k=a}^b f(k),$$ where $a,b$ are known, but I cant seem to get Mathematica to do ...
-3
votes
2answers
120 views

How to convert a matrix to MATLAB format? [duplicate]

I want to convert the following 16x16 matrix containing the variable n and some integers into matlab programming language: ...
3
votes
3answers
183 views

Permutations of 0's and 1's in a lower-triangular matrix

For a given $n \ge 5$ create every $n$-by-$n$ matrix containing exactly four $1$'s strictly below the diagonal and $0$'s elsewhere.
-1
votes
3answers
174 views

What would be a good way to implement index notation?

So I need to calculate a 3x3 rotation operator (basically a matrix). I have an index-notation expression, and I was wondering if with pre-calculated theta, K1, K2, and K3, could Mathematica compute ...
50
votes
6answers
4k 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 ...
0
votes
1answer
589 views

Solve equations real and imaginary part separately

For my system of equations, the procedure described in Solving complex equations of using Reduce works no more. How can I separate the real and imaginary part of ...
3
votes
0answers
74 views

Diagonalisation of equations for NDSolve

I have a linear matrix differential equation and I wish to speed up evaluation by diagonalising using eigenvectors. There is an example in Help for finite elements under "swinging beam" that is ...
4
votes
1answer
95 views

Speed up rendering of ContourPlot3D object

Please can you advise me how to speed up the rendering of the following two planes? When I click and drag to rotate the plot, its movement is quite jerky. Presumably it is working harder than I need ...
0
votes
1answer
122 views

Convert code from C++ to Mathematica [closed]

I need to know how to convert the following code in C++ to Mathematica. ...
3
votes
2answers
284 views

How do you create matrices using submatrix building blocks?

Here is a conundrum I am facing. I have $2$ matrix building blocks. In my problem, I associate integer $2$ with $3\times 3$ matrix $A$ with structure \begin{bmatrix} 0& a& 0\\ c& 0& ...
1
vote
1answer
137 views

Plotting a list of Eigenvectors

For my Fractional Calculus course, I was asked to find a matrix that arbitrarily represents the second derivative. This eventually got me a tridiagonal matrix. I was letter asked to find the ...