ASTR/PHYS 7730
Lab Exercise 02

Exercise 0.

Check out this tutorial (or maybe this one) on the chmod command. Set up a directory where you will keep homework files for this class, and set its permissions so that you and ONLY you have read-write-execute permission. Keep it this way for the entire semester.

Exercise 1. Shell scripts

Create a file hello.sh that prints out to "stdout" (standard output) the following:

    Hello, world.
Put on the first line of your file the line
    #!/bin/sh
(no spaces before the "#"). Do an ls -l to see what the privileges are. Change them with chmod to be able to execute hello.sh as if it were a command:
    kepler> hello.sh
    Hello, world

Exercise 2. Intro to python

Check out the Python Programming Language Official Website. [Note: We will focus on Python 2, as it seems to be the Departmental default.] Go through the tutorial. http://docs.python.org/2/tutorial/ http://www.python.org/doc/essays/ppt/sd99east/sld004.htm

Create a file hello.py, which you can execute using

    python hello.py
such that it simply prints out
    Hello, world.

Exercise 3.

Write a python script prime.py that finds all prime numbers between 1 and 1000. include your code between two lines of equal signs in your lab03 file (as above).

Exercise 4.

Run through the matplotlib python plotting tutorial. Start off by plotting y=sin(x*x) in domain x=[0...10]

Then create a two column text file init.dat with enough x-y points such that when they are "dot-to-dot" connected, they form the initial of your first name. Then write a python script lab02.2.py that reads the file, and draws a plot of the data in init.dat with the points connected, and then dumps the output to a PNG file named lab02.2.png.

Hints: start off your script with something like this

import matplotlib as plt
from pylab import *
import numpy as np
x, y = loadtxt('init.dat', unpack=True, usecols=[0,1])
That'll get things started with data loaded into arrays x and y from your text datafile. Other things that might help: plot(x,y) plotted the connected the dots; matplotlib axis function helped adjust the domain and range (try "plt.axis"); xlabel(), ylabel(), and title() functions set the axis labels and title, respectively (ok pretty obvious); and finally savefig('filename.png') saved the figure to the specified file using a formation (PNG) indicated by the file extension (.png).

Exercise 5.

Write a python script that generates 10000 realizations of a normal variate. Plot a histogram of it. Estimate the mean, variance, skewness and kurtosis from your sample.

Focusing only on the kurtosos, examine a variate

X = np.sum(np.random.univariate(-1,1,N))
Try with N = 1,3,10,30... to see how many terms are needed for the statistics of X to be approximately Gaussian?