[SciPy-user] Matlab, Scipy and teaching science
H.FANGOHR at soton.ac.uk
Thu Oct 20 12:20:16 CDT 2005
> I'm new to this list, so let me introduce myself. I'm currently
> doing a Masters investigating ways to teach physics students how to
> modules. However, the question I am consistently coming up against
> is "Why not teach the students Matlab?". It's a very good point and
> one I can think up no clear answer for. If the students stay in
> Physics or a related field they will be using Matlab (and
> C/C++/Fortran if needed). Therefore is there any reason not to teach
> Matlab as the introduction to programming?
As Prabhu pointed out, I have recently replaced Matlab with Python in a
computing module I deliver to engineering students. They have very little
prior knowledge. Let me try to reply to some of your points, and provide
some further thought, partly based on this experience.
I know Matlab pretty well, and have experience teaching beginners using
it. While in my eyes Matlab is a very good collection of linear algebra
libraries and decent visualisation in the same package, the glueing
'matlab language' that is used to script these components together is
quite broken (from a teaching point of view). For example,
(i) you can have only one (globally visible) function per file. This is
confusing for students because I try to introduce the concept of
modularisation by suggesting to use functions to split up code. They find
this not useful, because then the code is distributed over several files
(!) and you can't see all the files at the same time on your screen. Also:
(ii) the name of the function is determined by the label of the function
inside the file that defines the function. However, other code (located
outside that file) will know the function under the name of the file (!)
it is saved in (without the required ".m" extension). You therefore have
two names which -- if you want to keep things tidy -- should always be the
same. This is another source for errors and frustration.
(iii) There are more odd things, for example try these statements at theh
matlab command prompt: "sum 10" or "cos pi" for some entertainment. If you
are a student, you might expect "10" and "0.0" as replies but you get "97"
and "0.4560 -0.2410". (I would have hoped to get an error message.) While
these are very entertaining challenges for the lecturer, this is clearly
confusing to the student. (Can you work out why this happens?)
It boils down to this: If you know how to program 'correctly' already, how
to design your programs and data structures well, then you can write
useful and structured code in Matlab (or in C for that matter). If,
however, you are trying to learn these abilities, then Python puts fewer
obstacles in the way than Matlab.
I have published a few of these thoughts here (if citing a paper helps for
your case): H. Fangohr. A Comparison of C, Matlab and Python as Teaching
Languages in Engineering. Lecture Notes on Computational Science 3039,
Above, I have outlined practical issues for complete beginners.
If you look slightly ahead, then Python supports the three most common
programing paradigms: imperative, functional and object oriented whereas
Matlab is (pratically) procedural (and it not really object oriented).
Python allows you to use these concepts but you can mix and match as you
like and ignore what you don't want to know and use. (This keeps the
barrier low to start using it, but keeps the door open to do quite
With respect to 'Matlab is THE software in industry': there is no doubt
that it is widely used in certain parts of science and engineering. (And
so for good reason: it is an interpreted high-level language that makes
your life easier than if you used Fortran or C for the same problem.)
However, there is a certainly a growing trend towards Python. I have
spoken with a representative from Airbus and was told that a number of new
projects use Python as the user interface (often with C or C++ underneath
whereever speed is required). Surprisingly, one of the reasons mentioned
why they move away from Matlab, is that it was too expensive. They also
expressed delight that students leaving our university would know (some)
I hope this is some useful information.
More information about the SciPy-user