{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm1a_solution - q2 =-1.0*q1%assign q2 as negative of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Computational Physics Phy 265 Midterm 1a (In-Class) Solution function [potential_table]=potential(q1,d) %POTENTIAL - a function to compute the potential on the x-axis %of a dipole centered about the origin and on the x-axis. %Call syntax - [potential_table]=potential(1.60e-19,1.53e-10) %Input - magnitude of a charge in C and separation between the charges in m %Output - plot of x vs. V and a table of x (column 1) vs. V (column 2) in V %File written by S.C. Tegler. Last modified 2/21/2011 % --------------------------------------------------------------------- format short e %numerical output as short sci notation
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: q2 = -1.0*q1; %assign q2 as negative of input q1 k = 8.988e9; %Coulomb constant in MKS X1 = -d/2.0; %x location of q1 X2 = d/2.0; %x location of q2 XP = -3.0*d:0.1*d:3.0*d; %x positions for potential,VP,calculations VP = k*q1*(sqrt((XP-X1).^(2))).^(-1) + k*q2*(sqrt((XP-X2).^(2))).^(-1); plot(XP,VP, 'sk' ) %begin plotting xlabel( 'x (meters)' ); ylabel( 'V (volts)' ); title( 'Dipole Potential' ); %end plotting XP=XP' %transpose row to col vector VP=VP' %transpose row to col vector potential_table=[XP VP] %print position, potential table to %command window...
View Full Document

{[ snackBarMessage ]}