# Tag Info

## Hot answers tagged matrix

36 votes

### How to check if a vector is an eigenvector of a matrix using mathematica?

You could use MatrixRank. Here is a function that does this: ...
• 124k
34 votes
Accepted

### How to show matrix multiplication step by step?

If you have Mathematica 10 you can use the new Inactive functionality ...
• 42.9k
31 votes

### How to subtract the column means from each row of a matrix?

It is there: Standardize[mat, Mean, 1 &]
• 133k
30 votes
Accepted

### Add a vector to a list of vectors

I recommend using Transpose twice since it is more efficient than other approaches. Moreover Plus has the ...
• 54.4k
29 votes
Accepted

### How get eigenvectors without phase jump?

The phase (and length) of the eigenvectors is completely undetermined unless you specify extra conditions in addition to the eigenvalue equation. Given that you don't have any additional conditions, ...
• 95.3k
29 votes

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

As Daniel Lichtblau suggested in the comment, ArrayFlatten is the way. ArrayFlatten[{{A1, A2}}] // MatrixForm gives your ...
• 5,069
29 votes
Accepted

### Speeding up generation of block diagonal matrix

You are right, it can be done in a fraction of second. One can explicitly construct an array of indexes ...
• 42.9k
28 votes
Accepted

### Longest path in 0/1 matrix

As I expressed in my comment above, it is possible (and easy) to use the image processing functions for this. Taking m to be the matrix above the following steps ...
• 87.1k
28 votes
Accepted

### Speed up Do loops in MMA 13.0

Here's the fastest I've found: ...
• 220k
26 votes
Accepted

### How to speed up RotationMatrix?

Having this problem so often, I also generated some tools to handle it which I'd like to share. This is the code (along with a usage message which is basically a small modification of ...
• 96.3k
25 votes

### How to subtract the column means from each row of a matrix?

Well, transposing, subtracting, transposing... Transpose[Transpose[mat] - Mean[mat]]
• 111k
24 votes
Accepted

### How to interpret the results of PCA

I generated a multivariate data set to play with called fakedata (see at the bottom of the post). This contains five groups of samples, each in 25-replicate. Each ...
• 61.6k
23 votes
Accepted

### How do I create a triangulated surface from points?

It turns out ListSurfacePlot3D does a terribly poor job of approximating the surface in the OP, otherwise one will just apply ...
• 32.5k
23 votes
Accepted

### Nearest Kronecker Product

The Pitsianis-Van Loan algorithm turns out to be surprisingly easy to implement in Mathematica: ...
23 votes
Accepted

### How to subtract the column means from each row of a matrix?

mat - ConstantArray[Mean[mat], 3] or more generally: mat - ConstantArray[Mean[mat], Length[mat]]
• 36.9k
23 votes

### How to roll a graph on the y-axis

We calculate the tangent vector of parametric curve {t^2,t} and the ArcLength from 0 to <...
• 35.9k
22 votes

### The magic square function

@Nasser's answer is nice, but slowly when Mod[n,4]==0. Here is a faster code, efficiency is close to Matlab : ...
• 14.2k
22 votes
Accepted

### How can I reproduce the result of PrincipalComponents

I vastly prefer the formulation in terms of the singular value decomposition (SVD). This question gets asked a lot by users of these functions, so here's a quick reference: ...
22 votes

### What are the counterparts in Wolfram to left and right division of a matrix in other programming language, e.g. Julia and MATLAB?

I just stumbled upon it! At least when storing the factorization in a LinearSolveFunction object, we can use it for the transposed solve by supplying a further (not ...
• 96.3k
22 votes
Accepted

### Efficiently defining a SparseArray function

The way the code is written, you can neither exploit packed arrays nor any vectorization. There are two major reasons: Using Rule prevents using packed arrays ...
• 96.3k
22 votes
Accepted

### Can someone boost even more my code?

Exploitation of low rank structure The ordering of summation/dot products is crucial here. As aooiiii pointed out, mat2 has a low-rank tensor product structure. So ...
• 96.3k
21 votes
Accepted

...
• 8,427
21 votes

### Replace interior of matrix with zeros

You can do: x[[2 ;; -2, 2 ;; -2]] = 0; x or ...
• 133k
21 votes

### Why is calling Dot with many arguments so inefficient?

Here's an edited version of my answer to a related question (elsewhere). Since your central question was about speed (or time complexity), you might wish to know an important result from elementary ...
• 36.3k
21 votes
Accepted

### Sparse Cholesky Decomposition

LinearSolve[] actually computes a permuted Cholesky decomposition; that is, it performs the decomposition $\mathbf P^\top\mathbf A\mathbf P=\mathbf G^\top\mathbf G$....
21 votes

### What are the counterparts in Wolfram to left and right division of a matrix in other programming language, e.g. Julia and MATLAB?

The documentation for MATLAB's mrdivide states that The operators / and \ are related to each other by the equation B/A = (A'\B')' In light of this we may ...
• 68.9k
21 votes
Accepted

• 114k
20 votes

### Get the coefficient matrix from a quadratic form

Here is a very short solution: qf = a x^2 + b y^2 + c z^2 + 2 d x y + 2 e x z + 2 f y z; 1/2 D[qf, {{x, y, z}, 2}] (* ==> {{a, d, e}, {d, b, f}, {e, f, c}} *) ...
• 95.3k

Only top scored, non community-wiki answers of a minimum length are eligible