hw2_solns - # the number of points rather than the step size

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

View Full Document Right Arrow Icon
from pylab import * ################## # Problem 1 ################# def expdecay(x,lam=1.,A=1.): return A*exp(-x*lam) def dampedsine(x,lam=1.,k=1.,A=1.): apass=A lampass=lam return expdecay(x,lam=lampass,A=apass)*sin(k*x) def gauss(x,A=1.,sig=1.,x0=5.): return A*exp(-(x-x0)**2/sig) x=arange(0,10,0.02) subplot(211) #following commands go to the upper (1) plot plot(x,dampedsine(x,lam=0.4,k=10),'r<') title("A damped sine curve") xlabel("Time (S)") ylabel("Displacement (m)") subplot(212) #following commands go to the lower (2) plot plot(x,gauss(x, x0=x[len(x)/2]),'g-.',linewidth=2) title("A Gaussian function") xlabel("Frequency (Hz)") ylabel("Signal (mV)") #This tweaks the layout of the subplots so labels don't overlap. subplots_adjust(hspace=0.4) #show() ####################### #Problem 1b - Add a second figure ###################### figure(2) b=4 #Can use "linspace" as an alternative to "arange" either work # but linspace includes the final point and you give it
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: # the number of points rather than the step size theta=linspace(0,2*pi,200) #Eccentricity eps1=0.8 eps2=0.4 # Polar equations for an ellipse r1=b/sqrt(1-eps1**2*(cos(theta)**2)) r2=b/sqrt(1-eps2**2*(cos(theta)**2)) polar(theta,r1,theta,r2) #Tweak the legend location legend(('Eps=%2.2f' % eps1, 'Eps=%2.2f' % eps2), loc=(.9,.9)) ########### #Quiver plot of dipole field ############ figure(3) #grid point spacing dx=0.05 #location and magnitude of charges d=0.83 x1,y1=(-d,0) x2,y2=(d,0) q1=+1 q2=-1 #Setup grid of point in x and y xvals=arange(-1,1,dx) yvals=arange(-1,1,dx) x,y=meshgrid(xvals,yvals) #Evaluate vector field on grid points h1=(x-d/2)**2+y**2 h2=(x+d/2)**2+y**2 U=q1*(x-d/2)/h1+q2*(x+d/2)/h2 V=q1*y/h1 +q2*y/h2 #Plot the vector field # #quiver(x,y,U,V,color='b') #colorcode arrows by magnitude qp=quiver(x,y,U,V,sqrt(U**2+V**2),scale=100) quiverkey(qp,0,10,20,30,labelpos='N') show()...
View Full 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

hw2_solns - # the number of points rather than the step size

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online