Friday, January 10, 2014

Python for Ece1250


I just started classes at the University of Utah for Computer Engineering after a 3.5 year gap. I graduated with a Computer Science degree in 2010. I have been working as a software engineer since then and have been very active in the opensource community.

The content of the course heavily relies on using Matlab which is proprietary and paid. A Matlab student licence costs around 100 $ and an individual license costs around 1900 $. Having to pay that much for a software that just does scientific calculation, data analysis, plotting etc in today's day sounds outrageous. There are several opensource and free options out there that work just as well and can be used at no cost. Lot of us students don't really have the money or would rather use it for other stuff than licensing fees for software that have free alternatives.

The two alternatives to Matlab I have considered are R and Python. Both are viable options. In this post I will be evaluating the use of Python. I will make a post about using R later.

In this post I will go over an very simple example of plotting a graph for Question 1.19 from our Book.

Python can be downloaded from http://www.python.org/getit/

Once we install python we need to install pip which is a package manager. Once you have pip installed it will take the pain out of installing additional python libraries.
Ubuntu users can install python and pip via apt-get using:

sudo apt-get install python2.7 python-pip
Mac users can install python using:

sudo easy_install pip

If you installed python using brew pip will be installed by default.

Windows users can install easy install and pip using the links below:

easy_install: http://www.lfd.uci.edu/~gohlke/pythonlibs/#setuptools
pip: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip

For the graphing we will be using matplotlib which can be easily installed using

pip install matplotlib

Now we can create a python file wit a few lines of code to plot the graph for our function.
The code can be found at https://gist.github.com/anantasty/8362969#file-question1_19-py

Then we create the function q which is basically the same thing as the q(t) function in the problem.We start out by importing the contents of pylab.
We then create q_array(t_array)
q_array(t_array) basically applies q(t) to every function in the array t_array

then we create t_array from 0.0 to 60 like the problem says with a step of 1

we then get s which is the result of applying q(t) on the array t_array.

we then plot the graph, label the axes and save the image.
Let me know what your thoughts are on using python in comparison to matlab.