This is the web version of EJS interface
EJS version 4.3.3.3
1. Title=Electric Field and Potential in One Dimension of 2 Charged Particles
2. Author=Andrew Duffy edited by lookang
3. Level=A level Pre university
4. Language=English
5. Abstract=remixed by lookang
6. CaptureTools=true
7. DataTools=false
8. LanguageTools=false
9. EmersionSupport=false
10. AppletColSupport=false
11. UseInterpreter=true
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension
NameValueTypeDimension

### Evol Page

 Indep. Var. Increment d xtest /dt= vxtest d vxtest /dt= Enet Solver RungeKutta AbsoluteTolerance=0.00001
// Field and potential from particle 1 if (xtest != x1) { E1 = k*q1/((xtest-x1)*(xtest-x1))*(xtest-x1)/Math.abs(xtest-x1); V1 = k*q1/(Math.sqrt((xtest-x1)*(xtest-x1))); } else { E1 = 1.0e12; V1 = 1.0e12*q1; } Enet = E1; Vnet = V1; // Field and potential from particle 2 if (show2) { if (xtest != x2) { E2 = k*q2/((xtest-x2)*(xtest-x2))*(xtest-x2)/Math.abs(xtest-x2); V2 = k*q2/(Math.sqrt((xtest-x2)*(xtest-x2))); } else { E2 = 1.0e12; V2 = 1.0e12*q2; } Enet = Enet + E2; Vnet = Vnet + V2; scale2 = 1.0; } else { E2 = 0.0; V2 = 0.0; scale2 = 0.0; } // Max x values of the functions if (showgraph) { plot1max = x1-0.01; plot2max = plot1max; if (show2) { showmidgraph = true; plot2max = x2-0.01; if (x2 < x1) { plot2max = plot1max; plot1max = x2-0.01; } else { if (x2 == x1) { showmidgraph = false; } } } else { showmidgraph = false; } } else { showmidgraph = false; } if (showVgraph) { plot1max = x1-0.01; plot2max = plot1max; if (show2) { showmidVgraph = true; plot2max = x2-0.01; if (x2 < x1) { plot2max = plot1max; plot1max = x2-0.01; } else { if (x2 == x1) { showmidVgraph = false; } } } else { showmidVgraph = false; } } else { showmidVgraph = false; } if (q1 > 0.0) { redness = 250; greenness = 0; blueness = 0; colorball1 = new java.awt.Color(redness,greenness,blueness); } else { if (q1 < 0.0) { redness = 64; // by lookang greenness = 64; // by lookang blueness = 250; colorball1 = new java.awt.Color(redness,greenness,blueness); } else { redness = 200; greenness = 200; blueness = 200; colorball1 = new java.awt.Color(redness,greenness,blueness); } } if (q2 > 0.0) { redness = 250; greenness = 0; blueness = 0; colorball2 = new java.awt.Color(redness,greenness,blueness); } else { if (q2 < 0.0) { redness = 64; // by lookang greenness = 64; // by lookang blueness = 250; colorball2 = new java.awt.Color(redness,greenness,blueness); } else { redness = 200; greenness = 200; blueness = 200; colorball2 = new java.awt.Color(redness,greenness,blueness); } } // qtest if (qtest > 0.0) { redness = 250; greenness = 0; blueness = 0; colorqtest = new java.awt.Color(redness,greenness,blueness); } else { if (qtest < 0.0) { redness = 64; // by lookang greenness = 64; // by lookang blueness = 250; colorqtest = new java.awt.Color(redness,greenness,blueness); } else { redness = 200; greenness = 200; blueness = 200; colorqtest = new java.awt.Color(redness,greenness,blueness); } }
// decided to just show only for particle 1 n 2 only // Calculating forces if (show2==false&&testc==false) // no particle 2 or test charge { F1 = 0; F2 = -F1; } else if (show2==true&&testc==false) // only particle 1&2 { F1 = -k*q1*q2/((x2-x1)*(x2-x1))*(x2-x1)/Math.abs(x2-x1); F2 = -F1; } else if (show2==false&&testc==true) // only particle 1&testcharge { F1 = -k*q1*qtest/((xtest-x1)*(xtest-x1))*(xtest-x1)/Math.abs(xtest-x1); F2 = -F1; } else if (show2==true&&testc==true) // all 3 particles { F1 = -k*q1*q2/((x2-x1)*(x2-x1))*(x2-x1)/Math.abs(x2-x1) - k*q1*qtest/((xtest-x1)*(xtest-x1))*(xtest-x1)/Math.abs(xtest-x1) ; //F1 = - k*q1*qtest/((xtest-x1)*(xtest-x1))*(xtest-x1)/Math.abs(xtest-x1) ; F2 = -F1; } else // debug { F1 = 0; F2 = -F1; }
//s_E1 = " {E_net} ="+$\\theta$+"1/(4*"+"$\\pi$"+"{$\\epsilon$_o})*{Q_1}/{r^2}"; // to make display 2.30=vx instead of 2.3000000001 s_E1 = " {E_net} ="+"$\\Sigma$"+"1/(4*"+"$\\pi$"+"{$\\epsilon$_o})*{Q}/{r^2}"; //s_E2 = double2String(mass1,1.)+"*( "+double2String(vtemp1,1000.)+") + "+ double2String(mass2,1.)+"*("+double2String(vtemp2,1000.) +") = ???? "; if ( testc ==true&&show2==false) { s_E2 = " {E_net} ="+"1/(4*"+"$\\pi$"+"*{8.85*10^ - 12})*("+double2String(q1,10.)+"){*1*e^-9}"+"/("+double2String(xtest-x1,10.)+"){^2}" ; } else { s_E2 = " {E_net} ="+"1/(4*"+"$\\pi$"+"*{8.85*10^ - 12})*("+double2String(q1,10.)+"){*1*e^-9}"+"/("+double2String(xtest-x1,10.)+"){^2}"+"+"+"1/(4*"+"$\\pi$"+"*{8.85*10^ - 12})*("+double2String(q2,10.)+"){*1*e^-9}"+"/("+double2String(xtest-x2,10.)+"){^2}" ; } //V s_V1 = " {V_net} ="+"$\\Sigma$"+"1/(4*"+"$\\pi$"+"{$\\epsilon$_o})*{Q}/{r}"; //s_E2 = double2String(mass1,1.)+"*( "+double2String(vtemp1,1000.)+") + "+ double2String(mass2,1.)+"*("+double2String(vtemp2,1000.) +") = ???? "; if ( testc ==true&&show2==false) { s_V2 = " {V_net} ="+"1/(4*"+"$\\pi$"+"*{8.85*10^ - 12})*("+double2String(q1,10.)+"){*1*e^-9}"+"/("+double2String(xtest-x1,10.)+"){}" ; } else { s_V2 = " {V_net} ="+"1/(4*"+"$\\pi$"+"*{8.85*10^ - 12})*("+double2String(q1,10.)+"){*1*e^-9}"+"/("+double2String(xtest-x1,10.)+"){}"+"+"+"1/(4*"+"$\\pi$"+"*{8.85*10^ - 12})*("+double2String(q2,10.)+"){*1*e^-9}"+"/("+double2String(xtest-x2,10.)+"){}" ; }
// case 1 inside mass 1 if (show2==false&&xtest <(x1+sizex1/2)&&xtest>(x1-sizex1/2)) { _pause(); } //case 2 inside mass1 if (show2==true&&xtest <(x1+sizex1/2)&&xtest>(x1-sizex1/2)) { _pause(); } //case 3 inside mass2 if (show2==true&&xtest <(x2+sizex2/2)&&xtest>(x2-sizex2/2)) { _pause(); }
PE = qtest*Vnet; KE = 0.5*mtest*vxtest*vxtest; TE= PE+KE;
if ( xtest < xmin ) xmin = xmin*1.2; if ( xtest > xmax ) xmax = xmax*1.2;

### display

double dv; public String double2String(double v,double divider){ if(v>0)dv=0.5; else if(v<0)dv=-0.5; else dv=0; return (int)(v*divider+dv)/divider+""; } // this code has to do with displaying the number 2.3 instead of 2.300000001 when using % %
EJSVIEW: Click link to view it's content
 Control variables:(testing)double,double,double
 title = "Electric Field and Potential in One Dimension" layout = border visible = true location = "161,321" size = "750,600"
 position = east layout = border
 position = center autoscaleX = false autoscaleY = false minimumX = xmin maximumX = xmax minimumY = -2000.0 maximumY = 2000.0 square = false title = "Electric Field (N/C) and Potential (V) in One Dimension" titleX = Position (m) majorTicksX = true titleY = "Electric Field (N/C) and Electric Potential (V)" majorTicksY = true
 x = x1 y = zeroval sizeX = sizex1*scalex sizeY = sizey1*scaley enabledPosition = true dragAction = zeroval = 0.0; style = ELLIPSE lineColor = colorball1 fillColor = colorball1
 x = x2 y = zeroval sizeX = sizex2*scalex sizeY = sizey2*scaley visible = show2 enabledPosition = true dragAction = zeroval = 0.0; style = ELLIPSE lineColor = colorball2 fillColor = colorball2
 x = x1 y = -150 enabled = false text = 1 elementposition = NORTH
 x = x2 y = -150 visible = show2 enabled = false text = 2 elementposition = NORTH
 points = 200 min = xmin max = plot1max variable = xval functionx = xval functiony = k*q1/((xval-x1)*(xval-x1))*(xval-x1)/Math.abs(xval-x1)+ k*q2*scale2/((xval-x2)*(xval-x2))*(xval-x2)/Math.abs(xval-x2) color = 200,150,0,255 stroke = 2 visible = showgraph enabled = false
 points = 200 min = plot1max+0.02 max = plot2max variable = xval2 functionx = xval2 functiony = k*q1/((xval2-x1)*(xval2-x1))*(xval2-x1)/Math.abs(xval2-x1) + k*q2*scale2/((xval2-x2)*(xval2-x2))*(xval2-x2)/Math.abs(xval2-x2) color = 200,150,0,255 stroke = 2 visible = showmidgraph enabled = false
 points = 200 min = plot2max+0.02 max = xmax variable = xval3 functionx = xval3 functiony = k*q1/((xval3-x1)*(xval3-x1))*(xval3-x1)/Math.abs(xval3-x1)+ k*q2*scale2/((xval3-x2)*(xval3-x2))*(xval3-x2)/Math.abs(xval3-x2) color = 200,150,0,255 stroke = 2 visible = showgraph enabled = false
 points = 200 min = xmin max = plot1max variable = xval functionx = xval functiony = "k*q1/(Math.sqrt((xval-x1)*(xval-x1)))+ k*q2*scale2/(Math.sqrt((xval-x2)*(xval-x2)))" color = 150,150,255,255 stroke = 2 visible = showVgraph enabled = false
 points = 200 min = plot1max+0.02 max = plot2max variable = xval2 functionx = xval2 functiony = k*q1/(Math.sqrt((xval2-x1)*(xval2-x1))) + k*q2*scale2/(Math.sqrt((xval2-x2)*(xval2-x2))) color = 150,150,255,255 stroke = 2 visible = showmidVgraph enabled = false
 points = 200 min = plot2max+0.02 max = xmax variable = xval3 functionx = xval3 functiony = k*q1/(Math.sqrt((xval3-x1)*(xval3-x1)))+ k*q2*scale2/(Math.sqrt((xval3-x2)*(xval3-x2))) color = 150,150,255,255 stroke = 2 visible = showVgraph enabled = false
 x = xtest y = zeroval sizex = 0.2 sizey = 107.0 visible = testc enabled = true dragaction = zeroval = 0.0; secondaryColor = colorqtest color = colorqtest
 x = xtest y = 12 sizeX = E1 sizeY = 0.0 scalex = 0.01 scaley = 0.01 visible = testc enabledPosition = false enabledSize = false style = ARROW lineColor = MAGENTA fillColor = MAGENTA lineWidth = 2
 x = xtest y = -12 sizeX = E2 sizeY = 0.0 scalex = 0.01 scaley = 0.01 visible = show2&&testc enabledPosition = false enabledSize = false style = ARROW lineColor = 0,200,200,255 fillColor = 0,200,200,255 lineWidth = 2
 x = x1 y = 0 sizeX = F1 sizeY = 0 scalex = 0.01 visible = show2&&testc==false enabledPosition = false enabledSize = false style = ARROW lineColor = 64,200,64,255 fillColor = 64,200,64,255 lineWidth = 2
 x = x2 y = 0 sizeX = F2 sizeY = 0 scalex = 0.01 visible = show2&&testc==false enabledPosition = false enabledSize = false style = ARROW lineColor = 64,200,64,255 fillColor = 64,200,64,255 lineWidth = 2
 measured = true
 x = 0 y = yE1 pixelSize = true visible = showgraph enabledPosition = true sensitivity = 50 dragAction = yE2 = yE1 - 300 text = %s_E1% font = Arial,BOLD,20 elementposition = NORTH lineColor = 200,150,0,255 fillColor = 200,150,0,255
 x = 0 y = yE2 pixelSize = true visible = showgraph&&testc enabledPosition = true sensitivity = 50 dragAction = yE1 = yE2+300 text = %s_E2% font = Arial,BOLD,16 elementposition = NORTH lineColor = 200,150,0,255 fillColor = 200,150,0,255
 measured = true
 x = 0 y = yV1 pixelSize = true visible = showVgraph enabledPosition = true sensitivity = 50 dragAction = yV2 = yV1 - 300 text = %s_V1% font = Arial,BOLD,20 elementposition = NORTH lineColor = 64,64,200,255 fillColor = 64,64,200,255
 x = 0 y = yV2 pixelSize = true visible = showVgraph&&testc enabledPosition = true sensitivity = 50 dragAction = yV1 = yV2+300 text = %s_V2% font = Arial,BOLD,16 elementposition = NORTH lineColor = 64,64,200,255 fillColor = 64,64,200,255
 position = south layout = VBOX
 position = south layout = grid:4,3,3,3 visible = false size = 300,120 border = 50 borderType = MATTE borderColor = CYAN
 value = At the location of the test charge. editable = false size = 200,40 font = Dialog,BOLD,18
 value = units are N/C (+ = right) editable = false font = Dialog,BOLD,18
 value = units are volts editable = false font = Dialog,BOLD,18
 value = From charged particle 1 editable = false foreground = MAGENTA font = Dialog,BOLD,18
 variable = E1 format = E1 = 0.## editable = false foreground = MAGENTA font = Dialog,BOLD,18
 variable = V1 format = V1 = 0.## editable = false foreground = MAGENTA font = Dialog,BOLD,18
 value = From charged particle 2 editable = false foreground = CYAN font = Dialog,BOLD,18
 variable = E2 format = E2 = 0.## editable = false foreground = CYAN font = Dialog,BOLD,18
 variable = V2 format = V2 = 0.## editable = false foreground = CYAN font = Dialog,BOLD,18
 value = Net field and potential editable = false font = Dialog,BOLD,18
 variable = Enet format = Enet = 0.## editable = false font = Dialog,BOLD,18
 variable = Vnet format = Vnet = 0.## editable = false font = Dialog,BOLD,18
 layout = VBOX
 layout = HBOX visible = show2&&testc==false
 variable = F1 minimum = -66.75 maximum = 66.75 format = "F1 = 0.00 nN" foreground = 64,200,64,255 tooltip = "Electric force due to particle 2 on particle 1"
 variable = F2 minimum = -66.75 maximum = 66.75 format = "F2 = 0.00 nN" foreground = 64,200,64,255 tooltip = "Electric force due to particle 1 on particle 2"
 layout = HBOX
 variable = E1 minimum = -66.75 maximum = 66.75 format = "E1 = 0.00 N/C" foreground = MAGENTA tooltip = "Electric field due to particle 1 on test charge"
 variable = E2 minimum = -66.75 maximum = 66.75 format = "E2 = 0.00 N/C" foreground = 0,200,200,255 tooltip = "Electric field due to particle 2 on test charge"
 layout = HBOX
 variable = showgraph selected = false background = 200,150,0,255 tooltip = "Show graph of the electric field due to particle 1 & 2 only"
 variable = E1+E2 minimum = -66.75 maximum = 66.75 format = "Enet = 0.00 N/C" foreground = 200,150,0,255 tooltip = "Total electric field due to particle 1 and 2 on test charge"
 layout = HBOX
 variable = V1 minimum = -1000 maximum = 1000 format = "V1 = 0.00 V" tooltip = "Electric potential due to particle 1 on position of test charge"
 variable = V2 minimum = -1000 maximum = 1000 format = "V2 = 0.00 V" tooltip = "Electric potential due to particle 2 on position of test charge"
 layout = HBOX
 variable = showVgraph selected = false background = 150,150,255,255 tooltip = "Show graph of the electric potential due to particle 1 & 2 only"
 variable = V1+V2 minimum = -1000 maximum = 1000 format = "Vnet = 0.00 V" tooltip = "Electric potential due to particle 1 and 2 on position of test charge"
 layout = HBOX visible = testc==true
 position = center variable = KE minimum = 0.0 maximum = 1.0 format = "KE = 0.0 J" tooltip = "kinetic energy of the test mass q of mass m"
 position = north variable = PE minimum = 0.0 maximum = 1.0 format = "PE= 0.0 J" tooltip = "poential energy of the test charge due to the potential field it is experiencing"
 position = south variable = TE minimum = 0.0 maximum = 1.0 format = "TE = 0.0 J" tooltip = "total energy possess by the test charge in this environment"
 position = center layout = HBOX
 layout = HBOX
 layout = VBOX
 position = north layout = HBOX
 text = " Q1 = " alignment = RIGHT background = colorball1 foreground = BLACK tooltip = "Charge on particle 1 = 0.# nC"
 variable = q1 format = "0.0" tooltip = "Charge on particle 1 = 0.# nC"
 text = " nC " alignment = RIGHT background = colorball1 foreground = BLACK tooltip = "nano Coulomb"
 variable = q1 minimum = -30.0 maximum = 30.0 orientation = HORIZONTAL ticks = 11 closest = true background = colorball1 tooltip = "Charge on particle 1 = 0.# nC"
 layout = VBOX
 layout = HBOX
 variable = show2 selected = false background = colorball2 tooltip = "two charged particles"
 text = " Q2 = " alignment = RIGHT background = colorball2 foreground = BLACK tooltip = "Charge on particle 2 = 0.# nC"
 variable = q2 format = "0.0" tooltip = "Charge on particle 2 = 0.# nC"
 text = " nC " alignment = RIGHT background = colorball2 foreground = BLACK tooltip = "nano Coulomb"
 variable = q2 minimum = -30.0 maximum = 30.0 orientation = HORIZONTAL ticks = 11 closest = true enabled = show2 background = colorball2 tooltip = "Charge on particle 2 = 0.# nC"
 layout = VBOX
 layout = VBOX
 layout = HBOX
 variable = testc background = colorqtest tooltip = "introduce test charge in nC"
 text = " q = " alignment = RIGHT background = colorqtest tooltip = "introduce test charge in nC"
 variable = qtest format = "0.00" tooltip = "introduce test charge in nC"
 text = " nC " alignment = RIGHT background = colorqtest tooltip = "nano Coulumb"
 variable = qtest value = 1 minimum = -5 maximum = 5 ticks = 11 closest = true background = colorqtest tooltip = "introduce test charge in nC"
 layout = HBOX
 text = " v =" tooltip = "velocity of the test mass, can be used to calculate the kinetic energy to verify conservation of energy"
 variable = vxtest format = "0.00E00" tooltip = "velocity of the test mass, can be used to calculate the kinetic energy to verify conservation of energy"
 text = "m/s " tooltip = "metre per sec"
 variable = t minimum = 0.0 maximum = 24*60*60*365 format = "t = 0.0E00 s"
 layout = HBOX
 variable = _isPaused enabled = testc==true imageOn = "/org/opensourcephysics/resources/controls/images/play.gif" actionOn = _play() imageOff = "/org/opensourcephysics/resources/controls/images/pause.gif" actionOff = _pause()
 image = "/org/opensourcephysics/resources/controls/images/stepforward.gif" action = _step() font = Dialog,BOLD,16
 image = "/org/opensourcephysics/resources/controls/images/reset.gif" action = _reset() font = Dialog,BOLD,16
 text = "?" action = if (helpFlag) { helpFlag = false; helpLabel = "Show Help"; } else { helpFlag = true; helpLabel = "Hide Help"; }
 layout = grid:0,1,0,0 visible = helpFlag onClosing = helpFlag = false; helpLabel = "Show Help"; location = "0,233" size = "785,210"
 value = Click and drag the test charge (the small red circle) left or right to sample the field at different locations. editable = false font = Dialog,BOLD,16
 value = Red indicates a positive charge, while blue indicates a negative charge. editable = false font = Dialog,BOLD,16
 value = The magenta arrow is the field from particle 1, the light blue arrow is the field from particle 2. editable = false font = Dialog,BOLD,16
 value = Use the sliders, in the menu at the right, to set the location of the charged particles and their charges. editable = false font = Dialog,BOLD,16
 value = Use the checkboxes at the top right to turn on or off the second charge, and to show or hide the graph. editable = false font = Dialog,BOLD,16
 value = "You can completely reset the simulation using the Reset Simulation button." editable = false font = Dialog,BOLD,16
 value = If you click in the graph area, you can read the coordinates in the yellow box at the bottom left. editable = false font = Dialog,BOLD,16
 value = The electric fields from the two particles, and the net field, are shown in the table at the bottom. editable = false font = Dialog,BOLD,16