hw1_soln

# hw1_soln - #Solutions to HW01 by JRG from pylab import...

This preview shows pages 1–2. Sign up to view the full content.

#Solutions to HW01 by JRG from pylab import * import time def sumnums(*nums): sum=0 for num in nums: sum+=num return sum def myavg(*nums): sum=float(sumnums(*nums)) return sum/len(nums) def stddev(nums): ''' sigma=stddev(sequence) returns the standard deviation of the sequence of numbers ''' from math import sqrt N=len(nums) avgnum=myavg(*nums) sum=0. for num in nums: sum+=(num-avgnum)**2 return sqrt(sum/N) def randseq(mean,sd,number,type='g'): import random seq=[] if type=='g': for i in range(number): seq.append(random.gauss(mean,sd)) elif type=='u': for i in range(number): seq.append(random.uniform(mean,sd)) else: print "The type of distribution is 'g' for gaussian (default) or 'u' for uniform" return return seq def myhist(x,binsize,low=False,high=False): ''' bins,counts = myhist(sequence,binsize,low=lowcutoff,high=highcutoff) If 'low' and/or 'high' are not supplied, they default to the min and max of sequence. A tuple of arrays (bins and counts) are returned.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/05/2010 for the course PHYS phy503 taught by Professor Gladden during the Spring '09 term at Ole Miss.

### Page1 / 2

hw1_soln - #Solutions to HW01 by JRG from pylab import...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online