MATLAB vs Python: for Scientific Computing — A Beginners Guide

Faisal Riyad
GradBunker
Published in
6 min readApr 20, 2018

Now a days “the ability to write codes” has become an essential skill for the students from the technical discipline. Either you like it or not, during your undergrad studies you will do assignments, solve equations or part of the problems of your project with some sort of coding. And, if you think of going for higher studies and doing some extensive research, then “writing codes” is a must know skill for you.

Which one you should learn — MATLAB or Python? There are no definite answers. MATLAB has been there for scientific computing for a long while, where as the development of scientific computing packages for python e.g. SciPy, NumPy have not been antiquated. So MATLAB has become a legacy language or tool for the scientific community.
It has become a legacy language for number of reasons. Engineers and Scientists always needed a programming language that expresses matrix and array mathematics directly, and then MATLAB (matrix laboratory) came into existence. MATLAB is a math and matrix oriented language comes with different types of specialized toolboxes (you have to pay for toolbox) for several purposes e.g. modelling economic data, image analysis or driving a robot. These toolboxes are professionally developed, rigorously tested and well documented for scientific and engineering applications. And that’s why you pay the price for it. On the other hand, in Python you often have to rely on community-authored packages for scientific and engineering usages.

Matrix Manipulation in Python vs MATLAB

MATLAB has a solid amount of functions. One of it’s best product is ‘SimuLink’, which has no alternative yet. You might of think another graphical programming language named ‘LabView’ as an alternative to it, but then you have to pay a heavy price for it. And, in Python to get that as a community developed package, we might have to wait for at least half of a decade.

It has extraordinarily good documentation to start learning, and a large scientific community who have either answered the questions that are going to be asked or will be answered by someone as you post them in the MATLAB Central. There are 365,000 contributors, 120 questions are answered and 25,000 sample scripts or codes are downloaded per day.

The best thing of MATLAB is the availability of GUI based apps for performing common tasks which makes the life of beginner easier. You don’t know how to fit a curve using ‘fminsearch’ command, you just open the data fitting toolbox, and with couple of mouse clicks it will be done. Parallel processing is much easier in MATLAB, if someone has access to the parallel computing toolbox. It has toolboxes for computational biology, computational finances, control systems, data science, image processing and computer vision, machine learning, physical modelling and simulation, robotics, signal processing and communications and IOT. Only disadvantages that i found, you have to pay for it and to some extent it requires a little bit of extra RAM in your computing device.

On the other side, calling Python as an alternative to MATLAB is technically incorrect, rather it is a general purpose programming language which means you can develop full fledged apps or other software tools in python. It is possible to create applications using any of the major GUI libraries (e.g. Qt), use OpenGL, drive your USB port, etc.

Python and its companion libraries are getting more and more sophisticated day by days. For large scale problems, Python is lot more expressive and readable as compared to MATLAB scripts. Python programs get structured through indentation i.e. code blocks are defined by their indentation which makes the program more easier to follow.

Indentation in Python

Being a free, cross-platform, general-purpose and high-level programming language, lots of people are now adopting Python. IDES like pycharm, ipython notebook, jupyter notebook an distributions like anaconda has made python far more usable for researchers. As a result of this popularity, plenty of Python scientific packages have become available with extensive documentation for data visualization, machine learning, natural language processing, complex data analysis and more. For example, scikit-learn includes start-of-the-art ‘Machine Learning’ approaches with very good documentation and tutorials.

Here i have collected the list of some popular Python scientific libraries and tools:

SciPy: This library is used by scientists, analysts, and engineers doing scientific computing and technical computing. It contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, signal and image processing, ODE solvers and other tasks common in science and engineering.

NumPy: It is the fundamental package for scientific computing with Python, adding support for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays.

Pandas: Pandas is a library for data manipulation and analysis. The library provides data structures and operations for manipulating numerical tables and time series.

SymPy: SymPy is a library for symbolic computation and includes features ranging from basic symbolic arithmetic to calculus, algebra, discrete mathematics and quantum physics. It provides computer algebra capabilities either as a standalone application, as a library to other applications, or live on the web.

Matplotlib: Matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib allows you to generate plots, histograms, power spectra, bar charts, errorcharts, scatterplots, and more.

scikit-learn: scikit-learn is a machine learning library. It features various classification, regression and clustering algorithms including support vector machines, random forests, gradient boosting, k-means and DBSCAN, and is designed to interoperate with the Python numerical and scientific libraries NumPy and SciPy.

scikit-image: scikit-image is a image processing library. It includes algorithms for segmentation, geometric transformations, color space manipulation, analysis, filtering, morphology, feature detection, and more.

Veusz: Veusz is a scientific plotting and graphing package designed to produce publication-quality plots in popular vector formats, including PDF, PostScript and SVG.

Astropy: The Astropy Project is a collection of packages designed for use in astronomy. The core astropy package contains functionality aimed at professional astronomers and astrophysicists, but may be useful to anyone developing astronomy software.

PsychoPy: PsychoPy is a package for the generation of experiments for neuroscience and experimental psychology. PsychoPy is designed to allow the presentation of stimuli and collection of data for a wide range of neuroscience, psychology and psychophysics experiments.

Biopython: Biopython is a collection of non-commercial Python tools for computational biology and bioinformatics. It contains classes to represent biological sequences and sequence annotations, and it is able to read and write to a variety of file formats.

There are so many packages around there, and the best thing is that they are free i.e. the scientific and numerical computing cost with Python is zero.

So, from a beginner perspective, there is no definite answer to the question: “Which one i should use for scientific computing?” I would like to answer this question in a different way. Using Python means you can more easily collaborate with people who don’t have access to MATLAB. Or, perhaps, you will use MATLAB, because there are no alternative packages in Python that serves as best as it do in MATLAB.

Please like and follow us on Facebook: https://www.facebook.com/gradbunker

References:

[1] https://www.mathworks.com/products/matlab/matlab-vs-python.html

[2] http://www.pyzo.org/python_vs_matlab.html

[3] https://bastibe.de/2013-01-20-a-python-primer-for-matlab-users.html

[4] http://lorenabarba.com/blog/why-i-push-for-python/

--

--