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

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern