Questions on the manipulation of matrices in Mathematica.

learn more… | top users | synonyms (1)

1
vote
3answers
118 views

Randomly changing matrix entries

Write a block of code that generates a 4x4 matrix with randomized real number entries each between 0 & 1, then selects 3 matrix entries at random, and finally replaces these 3 entries with ...
5
votes
1answer
507 views

Generating random symmetric matrix

Suppose first that I want to generate a matrix whose elements are independent and identically distributed (i.i.d.) with distribution dist. This is easy: ...
1
vote
1answer
144 views

Transform linear system into a matrix form

I have a system of linear equations in variables $A_n$ of form: $$ \sum _{k=-K}^K h_k A_{n-k} J_{n-k}\left(\frac{(1-i) \text{$\eta $Sqrt}(n-k)}{\sqrt{2}}\right)+A_n\left(\frac{(1-i) \eta ...
-1
votes
1answer
148 views

Strange bug involving a list, “Objects of unequal length” [closed]

sortedTally is a list generated from Tally sortedTally[[1]][[1]] is a list If I print: ...
3
votes
1answer
309 views

Plot 3D boolean Array or matrix in Mathematica

I have been attempting several methods to plot a 3D diagram of a n by n boolean array in Mathematica but none of them produced satisfactory result. I want the $3D$ plot to have a cube when ...
0
votes
1answer
58 views

How to count column occurrences in a matrix?

I have a matrix of data, and I want to count the number of columns that match, and have some way to organize them by frequency. But I don't want to count the entire column, but consider the matrix ...
1
vote
1answer
136 views

Why does Mathematica add Hold to the result of my user defined symbol?

In the code below I have defined a symbol that multiplies two block-matrices (I can't use the builtin Dot since Dot assumes that the matrix coefficients commute): ...
7
votes
2answers
340 views

Defining quantum-mechanical Bra and Ket operations

I have the following ket in the Fock basis: $\vert3, 0 ,1\rangle$, where each entry defines the number of photons in a particular mode and can take any one of the following numbers: 0, 1, 2, 3. As a ...
0
votes
1answer
87 views

whats wrong when I use for loop for creating a matirx? [closed]

When I use separate value for "i" and "j", I got the correct desirable answer. a = 2; i = 3; j = 3; !(*SubscriptBox[(matrix), ([([a])])]) = {{1, 1, 3}, {7, 4, 7}, {2, 6, 8}}; value = ...
1
vote
1answer
52 views

How to swap tensor indices without permutation?

Say I have a tensor of rank R, How to swap $i^{th}$ and $j^{th}$ tensor index? I do not want to use TensorTranspose because it requires to write down the entire permutation, i.e. ...
4
votes
1answer
150 views

Proving positive definiteness or semi-definiteness of a matrix

I have the following 4x4 real symmetric matrix: $K=\begin{bmatrix}3-3w & -\frac{4}{3}+a+2w & \frac{5}{12}+b-\frac{w}{2} & 0\\ -\frac{4}{3}+a+2w & -1-6a-3x & ...
3
votes
1answer
276 views

Principal Components - how to obtain linear transformations?

I have a list "xlsf" with 6 columns and 1200 rows for PCA analysis. The PrincipalComponents[xlsf] gives the following: "The principal components of matrix are ...
3
votes
1answer
215 views

Spectral Clustering

I am attempting to implement a spectral clustering routine using Mathematica, but I am encountering difficulties. Using the standard Gaussian similarity function found in section 2.2 of this paper ...
8
votes
3answers
372 views

Plotting triple data points while xy data are not regular

I plotted recently some figures in Matlab and their quality was not that satisfactory, so I come to Mathematica as my supervisor suggested. This is how such figure looks like in Matlab: . In Matlab, ...
10
votes
1answer
293 views

Drop selection of columns from a ragged array

I have an application where I need to drop some arbitrary list of columns from a ragged array (where of course the shortest array rows have at least all the specified columns). E.g., given a ragged ...
8
votes
2answers
554 views

Is there any fast way to solve a quadratic matrix equation in Mathematica approximately?

Let the square nonsingular matrix $M$ is a given convergent matrix. What are the best scalar values for $\alpha$ and $\beta$ (in the real numbers domain), at which the following quadratic matrix ...
4
votes
2answers
159 views

Improve simulation speed using Compile

I have two square matrices, a hermitian matrix h and an unitary matrix v. I am interested in the following function ...
0
votes
1answer
73 views

Creating Matrix,Inverted and Upper Triangulate inside Module

I was trying to fit this into a module but I didn't have any luck. And for some reason it won't Inverse the Matrix. Here's the code: Input: ...
88
votes
7answers
24k 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 ...
-1
votes
1answer
63 views

Help needed with assignment [closed]

Can I get some help with this: Write a module which as an input receives two matrices, the first matrix transforms in to the same matrix, but in the new matrix occur absolute values of the first, ...
6
votes
2answers
688 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: ...
0
votes
0answers
59 views

Which method to use for finding maximum without actually computing optimization function explicitly?

I am new to Mathematica and I am currently working on an optimization problem. The optimization function that I have easy to calculate for some assignment of variable but it is very difficult to ...
-1
votes
1answer
64 views

Module whose input is a function of 2 variables [closed]

I need to make a Module whose input is a function of 2 variables and 2 variables m,n so i can make a Matrix with Array. Basicaly, I need this: ...
1
vote
2answers
84 views

Matrix with infinity on main diagonal

The question is trivial, however, there might be unexpected solutions. What would be nice way to create a square matrix with $\infty$ on main diagonal, and some arbitrary constant everywhere else? My ...
2
votes
2answers
229 views

How to make Mathematica show matrices and vectors nicely

It shows me like {{0}, {1}, {0}, {-1}} . Is it possible to make it look like a vector, always?
3
votes
2answers
239 views

Binarizing a matrix

I have an image with a few bright pixels with the remaining ones very dark. The difference is in orders of magnitude. I want to binarize this matrix (corresponding to the image) making all values ...
0
votes
0answers
56 views

Does Mathematica support Laguerre Polynomials of Matrix Argument?

I am wondering whether Mathematica can also compute the Laguerre polynomials of matrix argument as the appear in multivariate statistics? For example, they appear in this paper here: ...
1
vote
1answer
102 views

Extract coefficient matrix $A$ from expression $f(x)$

I have expression: $$f(x)=\sum_{i=0}^{K-1}\sum_{j=0}^{N-1}a_{i,j}e^{ix}x^j.$$ I want to extract coefficient matrix $A$ from expression $f(x)$ where $$A=\left( \begin{array}{ccccc} a_{0,0}& ...
0
votes
1answer
60 views

Symbolically solve system of equations involving matrix

I need to solve the following system of equations symbolically for a_i, b_i, and c_i: ...
14
votes
3answers
615 views

Why is calling Dot with many arguments so inefficient?

Say I want to multiply a reasonably large list of symbolic matrices. ...
8
votes
3answers
966 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 ...
3
votes
1answer
133 views

$\mathbf L\mathbf D\mathbf L^\top$ Cholesky decomposition

Mathematica can do a Cholesky decomposition $\mathbf A = \mathbf L\mathbf L^\top$, but how do I do a LDL decomposition $\mathbf A = \mathbf L\mathbf D\mathbf L^\top$, with $\mathbf L$ being a unit ...
2
votes
0answers
79 views

Factor out a constant from a matrix

I've got a matrix in which every entry is of the form x/4. I cant find out how to factor out the 1/4 so that the actual matrix is clearer. Thanks for your help!
2
votes
1answer
58 views

Efficient Implementation of Resistance Distance for graphs?

Is there an implementation of the resistance distance matrix (or just resistance matrix) for graphs available in Mathematica?
0
votes
0answers
45 views

in the part assignment is not a symbol, create different matrices with a “Do” loop [duplicate]

Im trying to assemble new matrices from some previous matrices I have created, but I can´t. What Im trying to do is the following: 1) I have different matrices: ...
0
votes
1answer
54 views

Returning functions that are partly evaluated

I have some performance issues when calling Table[{h, Slow1[h, n]}, {n, nlist}, {h, 0.1, 10, 0.5}]; for a given list ...
1
vote
1answer
80 views

How to construct a kernel from a function?

I would like to convolve an image with a mathematical function. I understand that I need to have the mathematical function in a matrix form. How can I build it? Thanks
12
votes
1answer
264 views

Why does partitioning increase Dot execution speed?

I have noticed that multiplying a list of matrices can be significantly sped up by partitioning the list, calculating the product of the partitions matrices, and then multiplying the results. ...
1
vote
1answer
332 views

Usage of Piecewise/RSolve to solve an equation based on condition

I am trying to compute price of call option on a stock using the finite difference method. I have a VBA code for it, and I am trying to find out how I can use Mathematica memoization functions and ...
0
votes
1answer
71 views

Symbolic matrix inversion

If I try to get an inverse of a matrix: a | b | c b | d | 0 c | 0 | 0 Inverse[{{a, b, c}, {b, d, 0}, {c, 0, 0}}] I get the answer: ...
0
votes
3answers
60 views

Simplifying Terms in a Matrix

Given the following 3 matrices: M1=1/3*{{1,1,1},{1,α,α^2},{1,α^2,α]}} Z1={{Z+Zg,Zg,Zg},{Zg,Z+Zg,Zg},{Zg,Zg,Z+Zg}} M2={{1,1,1},{1,α^2,α},{1,α,α^2}} where alpha ...
0
votes
2answers
30 views
-1
votes
1answer
62 views

Beginner Question: Assigning an indexed Variable to a given list

I am pretty new to the game and have a problem, which i am sitting on for hours. 1) I created a random Matrix 5x5 ...
4
votes
1answer
73 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, Mod[n,4]==0 ...
1
vote
1answer
77 views

Divide each element of a list of 500 matrices by another matrix

Lets say that I have a Table of dimension (3,3,500) and I'd like to perform element-wise division by a 3x3 matrix along the third dimension (of length 500 in this case). What is the most elegant way ...
8
votes
3answers
698 views

The magic square function

There're some matrices that the sum of columns, sum of rows, and sum of diagonals are the same value. Here is an example: ...
1
vote
1answer
68 views

Assigning some results after a solve procedure to the coefficients of a matrix

I have a matrix M[3,3]. After a solve procedure, I obtained these results. {{M[1, 2] -> Cos[ψ[t]], M[1, 3] -> 0, M[2, 3] -> 0, Cos[θ[t]] -> M[3, 1], M[3, 2] -> 0, M[3, 3] -> 1, M[2, 1] -> ...
0
votes
0answers
41 views

Parametrizing a matrix given its trace and norm

I have a problem where I have to generate random matrices with the following properties: ($a$ is a given fixed number) $\mathrm{Tr}\, A=0$ $\mathrm{Tr}(A^\dagger A)=\|A\|_F^2=a$ I was wondering ...
4
votes
4answers
130 views

Express block matrix in terms of matrix basis

I'm trying to construct a function that returns the multiplication table of a matrix Lie algebra. Assuming a basis of matrices, my definitions: ...
-1
votes
1answer
97 views

Laplace equation

I tried to run this code, but it doesn't work for NDSolve ...