CLab_Instructions-1
CLab_Instructions-1
You should not have any difficulty in finding the computer lab. It is in the top floor, above the non-electrical
lab. You have to enter the lab keeping your footwear outside the lab door (with the glass panel).
Each of you will be assigned a separate desktop, but there is no reserved desktop for you, and next day you
may have to use a different one. Anyway, we will delete all the files created by you at the end of the day, so if
you want to keep a copy for yourself, maybe for further editing at your home, please do not forget to take the
copy using a pen drive (aka USB stick). The desktops are not connected to the internet, so you cannot back
up your files using net.
The Operating System (OS) is Ubuntu Linux in all the desktops, there are no Windows. There is a user
account for you where you must log in to proceed further. For most of the machines, the account name is
msc and the password is msc123 --- you will also need the password to unlock your screen if it gets locked
due to inaction. There are some desktops with a different user account and password, which should be
indicated clearly just behind your desktop. You have to work in the “Terminal”, using a text editor. The
Terminal can be found in the bar at the left of the screen (called the dock). If it is not there, call one of your
teachers and (s)he will help you.
The standard text editor is gedit. You open a file in the Terminal (not within the Python environment!),
using the command
gedit filename
The filename can be anything you want, but if you are writing a Python program, it should have an extension
.py --- like myfile.py --- where you write your program. Do not forget to save whatever you have
written before trying to execute it. Use the save option of gedit.
After opening the Terminal, see if Python3 is running. Type, at the shell prompt that goes something like
...-msc$$
python3
and you will get the >>> prompt. This is the Python environment, where you can execute the commands.
Check, in the >>> prompt, whether numpy, scipy, and matplotlib can be imported. Just type
>>> import numpy
>>> import scipy
>>> import matplotlib
If they do not give any warning message, you are ready to start. If you get a message that they cannot be
imported (just check with numpy and that should be enough), you have to type python, and work with
Python2. The programs are simple enough and you can use either Python2 or Python3, but there are some
differences in defining variables and commands like print.
In Python, you can input every line of the program separately at the >>> prompt. But that is not a very good
way of programming. You should write the entire code in a file (use gedit, and do not forget the .py
extension). Say you name the file problem1.py (the extension has to be py). Then run the entire file with
python3 problem1.py
Import numpy, scipy, matplotlib, and whatever else you need (if permitted), as command lines in the
file. Python will compile one line at a step, and tell you if there is something wrong. We may help with the
logic, but we will in general assume that you know the Python syntax.
Once your program runs, and you get an output, copy the output in another file, name it whatever you want.
Suppose your program file is problem1.py and the output file is xyz. Then prepare the final file that you
should submit, using the command
cat problem1.py xyz > ClassRoll_ProblemSet#_ProblemNo.txt
Do not forget the spaces and the > sign.
The filename should have a format like ClassRoll_ProblemSet#_ProblemNo.txt. For example, if your Class
Roll number is 01, and the file is for Problem 3 of Problem Set 2, the filename has to be
01_ProbSet3_2.txt
Please stick to this format, otherwise it will be hard for us to find your works later. Note the extension .txt,
that is the standard one for any text file. For problems with two or more parts, join all the files:
cat problem1a.py xyz problem1b.py abc > 01_Probset1_1.txt
If, for some reason, the program does not compile, or does not give any result, just submit the program. We
will collect all the files that you create, and feel ready for submission, at the end of the day. Of course you
can keep a copy.
Last line: Don’t ever try to copy programs from your friend. You will rue that.
Here is a sample python program. If this works, you should not have any problems in compiling.
import numpy as np
import pylab as pl # you can also use matplotlib if you don't want plots
sum1 = a1 + a2
divide1 = a1 / a3
sq = np.sqrt(a3)
# Plot
x = np.linspace(1, 30, 100) # To set the range, 1 to 30, with 100 points
y = np.sin(x)
pl.plot(x, y)
pl.xlabel('$x$')
pl.ylabel('$\\sin(x)$') # See how the label comes without the two \\
pl.show()