Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm taking a linear algebra / matrix theory course and we are free to use any software we want, and will be "expected to use MATLAB or an equivalent" for homework. The professor and textbook (Applied Linear Algebra) prefer MATLAB, some students seem to like R, but I'm already familiar with Mathematica and have a student license.

Are there any possible limitations of Mathematica to watch out for, if used as a learning device (i.e. not for work or intensive computation) for a linear algebra course? e.g. Are there some operations which the other software packages can do which Mathematica cannot out-of-the-box?

share|improve this question
Could you mention the textbook you're using? –  J. M. Sep 8 '12 at 7:36
There is a book focused on teaching linear algebra with Mathematica, which you can get used from Amazon. It is pretty dated, and I don't know how good it is, but if you decide to go with Mathematica, it may be of some help. –  Leonid Shifrin Sep 8 '12 at 9:00
If prices of licence is the issue you might want to try python numpy library as well. Or Octave for Matlab clone. –  enedene Sep 8 '12 at 12:34
@enedene I find freemat or scilab to have a more reasonable frontend than octave, an they're equally free (although maybe their licenses are more restrictive, I don't know). overall I'd go with matlab or python if not mathematica though. in any case as he has a student license I don't think this is important. –  acl Sep 8 '12 at 13:05
@Nasser Agree 100%. This was and still is my most difficult transition coming from Excel and MATLAB was the "Lists of lists" concepts. Also, MATLAB has some cool notation for solving linear systems such as Ax=b can be solved by A\b. –  kale Sep 8 '12 at 13:17
show 2 more comments

3 Answers

up vote 15 down vote accepted

Mathematica offers a pretty complete set of functionality for linear algebra, and it has improved in recent versions.

For example, since version 5, Mathematica has offered the generalised Schur decomposition (also known as the QZ decomposition). This certainly wasn't available in earlier versions. It handles sparse matrices and many other wrinkles. And if it isn't available, this example shows that it can take a lot less code than in many other languages, so you are less likely to get yourself tangled up in loop constructs and the like.

Rather than focus on limitations, I thought it worth mentioning that Mathematica offers something neither Matlab nor R can, that makes it ideal as a pedagogical tool: integrated symbolics. If you are learning linear algebra and you want to understand certain things, you can in many cases pass a symbolic matrix to the relevant function, and use the resulting output to gain a deeper understanding.

Here's a simple example:

aa = Array[a, {2, 2}]

(* {{a[1, 1], a[1, 2]}, {a[2, 1], a[2, 2]}}*)


(*{1/2 (a[1, 1] + a[2, 2] - Sqrt[
    a[1, 1]^2 + 4 a[1, 2] a[2, 1] - 2 a[1, 1] a[2, 2] + a[2, 2]^2]), 
 1/2 (a[1, 1] + a[2, 2] + Sqrt[
    a[1, 1]^2 + 4 a[1, 2] a[2, 1] - 2 a[1, 1] a[2, 2] + a[2, 2]^2])}*)

Of course, sometimes the symbolic output is pretty hard to trace through (consider SingularValueDecomposition[aa] for the aa defined above!), but in can be useful in some cases.

Some pages on the internet contain claims that Mathematica is slower than Matlab, or that Matlab is somehow "better" for numerical work (and implicitly, Mathematica is only good for a bit of symbolic solving or something). As this answer shows, this claim is no longer true. It was true until about version 5, but no longer.

share|improve this answer
Congrats on your 10k! –  Sjoerd C. de Vries Sep 8 '12 at 8:55
add comment

In years past I've taught a standard-content sophomore-level (in U.S.) linear algebra course where students used Mathematica. I know, then, that if you're interested, or if it's a requirement, you can build everything up from the simplest functions for manipulating matrices or you can directly use powerful built-in Mathematica functions (or a combination of both).

E.g., you might begin by defining little utility functions to scale a row, to swap two rows, and to add one row to another; from that, you can build a function to do Gauss-Jordan row reduction. Or you can directly use RowReduce.

Again, you might define a function to test for invertibility and, when invertible, find the inverse of a matrix by adjoining an identity matrix, row reducing, etc. Or you can directly use Inverse.

Even for something more complicated like Gram-Schmidt orthonormalization, you can build up a function for this yourself, beginning by defining a function that projects a vector onto the span of a given set of vectors. Or use Orthogonalize.

You could even define your own determinant function (in one of several ways), then use that to find eigenvalues, etc.

If your course involves advanced operations such as LU or QR decompositions, again you can define functions for these yourself or else use the built-in ones.

Of course in general you would expect built-in functions to handle round-off issues more robustly than anything you would program yourself. But this would be the same with Matlab.

So yes, Mathematica would be an entirely appropriate tool in place of Matlab.

share|improve this answer
is there any chance you can add a link to the course notes? –  user21 Sep 9 '12 at 1:24
@ruebenko: I considered doing so and still could. But the notebooks are 10 years old now, and some of the files are .m packages encoded for the Windows/PC platform. (Students would define a function, then run an encoded package that tested it with various sets of data against my "correct" but encoded version of the function.) –  murray Sep 9 '12 at 15:00
add comment

Having taught linear algebra using both Mathematica and Matlab, I concur with what others have said that the Mathematica's features for linear algebra include all one might need for a course in undergraduate linear algebra. Since symbolic computation is also fully integrated into Mathematica, it might be better in some ways. For example, we can solve symbolic systems of small dimension fairly easily.

LinearSolve[{{a, b}, {c, d}}, {e, f}]

enter image description here

Note how the determinant appears in the denominator illustrating its importance in determining when a system is solvable. This can be done just as easily for a 3x3 or 4x4 system.

Also, there is a common mis-conception that Mathematica does not or cannot distinguish between row and column vectors, as illustrated by Nasser's comment. I think this is not correct. It's just that if you want to represent a row or column vector, you should use the full matrix representation of said vector. Consider, for example, the following two dot product computations (whose orders cannot be reversed):

{{a, b}, {c, d}}.{{x}, {y}} // MatrixForm

enter image description here

{{x, y}}.{{a, b}, {c, d}} // MatrixForm

enter image description here

In addition, though, Mathematica provides a consistent notion of dot product between dimensions based on tensor products. Here's the product of a rank 3 tensor with a rank 2 tensor.

Table[a[i, j, k], {i, 1, 2}, {j, 1, 2}, {k, 1, 2}].
  Table[b[i, j], {i, 1, 2}, {j, 1, 2}]

enter image description here

By contrast, Matlab is limited to 2D floating point matrices. When you type x=2 in Matlab, you've defined a 2D matrix; the equivalent definition in Mathematica would be x={{2}}.

share|improve this answer
@NasserM.Abbasi I guess I disagree with the documentation. The example shows that, if you represent a vector using a rank 1 tensor, then you can't distinguish between left and right multiplication. I'm saying that you can distinguish between left and right multiplication, if you represent a vector as a rank 2 tensor. –  Mark McClure Sep 9 '12 at 11:10
@NasserM.Abbasi Of course, you can define higher rank objects in Matlab. You can even use cell arrays to define fairly arbitrary objects. I guess I mean to say that the default in Matlab is a 2D float and support beyond that is lacking. For example, the 3D and 4D matrices that you define (which we'd call rank 3 and 4 tensors in the Mathematica context) cannot be multiplied using the * operator in Matlab. The corresponding tensors can be multiplied in Mathematica using Dot. –  Mark McClure Sep 9 '12 at 11:15
For better or worse, vectors, matrices, etc., in Mathematica are just lists. For pedagogical purposes this is not necessarily optimal. Before I taught linear algebra with Mathematica, I did so with APL and later J. In each of those languages, a vector is a 1-dimensional creature, whereas a row vector or a column vector is a 2-dimensional creature, namely, a 1-row or 1-column matrix. –  murray Sep 9 '12 at 15:04
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.