2.1 introduction

Mathematica and Matlab allow one to do pretty much the same operations in the area of linear algebra and matrix manipulation. Two things to keep in mind is that Mathematica uses a more general way to store data.

Mathematica uses ragged arrays or a list of lists. This means rows can have different sizes. (these are the lists inside the list). So a Mathematica matrix is stored in a list of lists. This is similar in a way to Matlab cell data structure, since each raw can have different length. In a standard matrix each row must have the same length.

In Matlab one can also have ragged arrays, these are called cells. In Mathematica, there is one data structure for both.

Another thing to keep in mind is that Matlab, due to its Fortran background is column major when it comes to operations on matrices. This simple example illustrate this difference. Suppose we have a matrix \(A\) of 3 rows, and want to find the location where \(A(i,j)=2\) where \(i\) is the row number and \(j\) is the column number. Given this matrix \[ A = \left ( {\begin {array}{cccc} 1 & 2 & 3 & 4 \\ 2 & 3 & 1 & 5 \\ 5 & 6 & 7 & 2 \end {array}} \right )\] Then the result of using the find() command in Matlab is

A=[1 2 3 4; 
   2 3 1 5; 
   5 6 7 2]; 
[I,J]=find(A==2)
 
I = 
     2 
     1 
     3 
J = 
     1 
     2 
     4 
     ]
 

The Matlab result gives the order of the rows it found the element at based on searching column wise since it lists the second row first in its result. Compare this to Mathematica Position[] command

mat = {{1, 2, 3, 4}, 
       {2, 3, 1, 5}, 
       {5, 6, 7, 2}} 
Position[mat, 2]
 

which gives

{{1,2}, 
 {2,1}, 
 {3,4}}
 

Mathematica searched row-wise.

I found Mathematica for matrix operations takes more time to get familiar with compared to Matlab’s, since Mathematica data structure is more general and therefore a little more complex (ragged arrays, or list of lists is its main data structure) compared to Matlab’s. This is because Mathematica has to also support symbolics in its commands and not just numerical data.

In Maple the following short cuts can be used enter vectors and matrices: For row vector:  v:=<1|2|3|4> and for column vector  v:=<1,2,3,4> and for a Matrix of say 2 rows and 3 columns  A:=<1,2|3,4|5,6>. Here | acts as a column separator. For transpose of matrix,  A^%T is the short cut notation.