***Appendix A_2***

The following Visual Basic code produces the data plotted in the Figures of Sect. 2.

Option Explicit

Private Sub cmdSect2_Click()

'*********************************

'Compute the electric and magnetic fields, and the Poynting vector, at two points on the

'y-axis, for an oscillating point charge. Output Ex, Bz and Py for plotting purposes.

'*********************************

'Constants follow.

Const pi As Double = 3.14159265

Const eps0 As Double = 0.00000000000885

Const c As Double = 299792000

Const steps As Long = 5000 'Number of time epochs in one cycle

Const Ampl As Double = 0.001 'Amplitude of oscillation

Const vmax As Double = 0.01 * c

Const omega As Double = vmax / Ampl 'Angular frequency of oscillation

Const freq As Double = omega / (2 * pi) 'Frequency of oscillation

Const tau As Double = 1 / freq 'Period of oscillation

Const deltat As Double = tau / steps 'Time interval between epochs

Const q As Double = 1 'Magnitude of point charge

Const lambda As Double = 2 * pi * c / omega 'Wavelength

Const neary As Double = lambda / 10 'Nearest field evaluation point

MsgBox ("Near y = " & neary)

Const fary As Double = 5 * lambda 'Farthest field evaluation point

MsgBox ("Far y = " & fary)

'Retarded quantities that are constant for this motion.

Const yr As Double = 0 'Retarded positions

Const zr As Double = 0

Const vry As Double = 0 'Retarded velocities

Const vrz As Double = 0

Const ary As Double = 0 'Retarded accelerations

Const arz As Double = 0

'*********************************

'Comment out the appropriate D component for the current field evaluation point

'Const Dy As Double = neary

Const Dy As Double = fary

'*********************************

Const Dz As Double = 0 'Displacement from retarded position to field eval point

Const uz As Double = 0 'Utility vector u

Const K1 As Double = q / (4 * pi * eps0) 'Saves cpu time

Const K2 As Double = eps0 * c ^ 2

'Variables follow.

Dim Ex(steps), Ey(steps), Ez(steps) As Double 'Electric field, E

Dim Bx(steps), By(steps), Bz(steps) As Double 'Magnetic field, B

Dim BzOut(steps) As Double 'This is Bz multiplied by c (for output/plotting)

Dim Sx(steps), Sy(steps), Sz(steps) As Double 'Poynting vector, S

Dim t(steps) As Double 'Current time

Dim tr As Double 'Retarded time

Dim ux, uy As Double

Dim Dx, D As Double

Dim index As Long 'For loop index

Dim dt As Double 'Current time minus retarded time

Dim xr As Double

Dim vrx As Double

Dim vr As Double 'Retarded velocity

Dim arx As Double

Dim dtmin, dtmax As Double 'Trial values of dt

'Executable code follows.

'Begin by setting up the (current) time epochs.

For index = 0 To steps - 1

t(index) = index * deltat

Next index

'Then for each time epoch...

For index = 0 To steps - 1

'Compute the retarded time.

dtmin = 0

'

'************************************

'Comment out the appropriate statement for dtmax

'**********************************************

'dtmax = Sqr((2 * Ampl) ^ 2 + neary ^ 2) / c

dtmax = Sqr((2 * Ampl) ^ 2 + fary ^ 2) / c

'************************************

Do

dt = (dtmin + dtmax) / 2

tr = t(index) - dt 'Trial retarded time

xr = Ampl * Sin(omega * tr) 'Trial retarded x

Dx = -xr

D = Sqr(Dx ^ 2 + Dy ^ 2 + Dz ^ 2)

If Abs(c * dt - D) < 2 ^ -30 Then Exit Do 'Test for best retarded time

If (c * dt - D) > 0 Then dtmax = dt

If (c * dt - D) < 0 Then dtmin = dt

Loop

'Once the retarded time is known, calculate the retarded kinematic variables.

vrx = omega * Ampl * Cos(omega * tr)

vr = vrx

arx = -omega ^ 2 * Ampl * Sin(omega * tr)

ux = c * Dx / D - vrx

uy = c * Dy / D

'Then compute the electric field...

Ex(index) = K1 * D / (Dx * ux + Dy * uy + Dz * uz) ^ 3 * (ux * (c ^ 2 - vr ^ 2) + Dy * (ux * ary - uy * arx) - Dz * (uz * arx - ux * arz))

Ey(index) = K1 * D / (Dx * ux + Dy * uy + Dz * uz) ^ 3 * (uy * (c ^ 2 - vr ^ 2) + Dz * (uy * arz - uz * ary) - Dx * (ux * arz - uz * arx))

Ez(index) = K1 * D / (Dx * ux + Dy * uy + Dz * uz) ^ 3 * (uz * (c ^ 2 - vr ^ 2) + Dx * (uz * arx - ux * arz) - Dy * (uy * arz - uz * ary))

'...and the magnetic field...

Bx(index) = 1 / (c * D) * (Dy * Ez(index) - Dz * Ey(index))

By(index) = 1 / (c * D) * (Dz * Ex(index) - Dx * Ez(index))

Bz(index) = 1 / (c * D) * (Dx * Ey(index) - Dy * Ex(index))

'Scale the magnetic field by a factor of c, so that it is comparable to Ex for plotting purposes.

BzOut(index) = c * Bz(index)

'...and finally the Poynting vector.

Sx(index) = eps0 * c ^ 2 * (Ey(index) * Bz(index) - Ex(index) * By(index))

Sy(index) = eps0 * c ^ 2 * (Ez(index) * Bx(index) - Ex(index) * Bz(index))

Sz(index) = eps0 * c ^ 2 * (Ex(index) * By(index) - Ey(index) * Bx(index))

Next index

'Once the fields and Poynting vector have been computed, output selected components for plotting.

Open "c:\WINMCAD\Physics\ElecDyn\Sect2\Sect2.PRN" For Output As #1

For index = 0 To steps - 1

Write #1, t(index), Ex(index), BzOut(index), Sy(index)

Next index

Close

MsgBox ("Ready for plotting data")

Stop

End Sub