Option Explicit

Private Sub cmdComputeExConstdadt_Click()

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

'Compute Ex at points on the y-axis ranging from y=1m to y=.001m.

'Use the motion specified by Eqs. 1a-d in "A Real-Life Example of the

'Radiation Reaction Force." Output the computed values

'of Ex for plotting purposes.

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

'Physical and mathematical constants follow.

Const c As Double = 299792000 'Speed of light

Const epsilon0 As Double = 0.00000000000885 'Permittivity Constant

Const pi As Double = 3.14159265358979

Const Steps As Long = 5000 'Number of y-axis points

Const Pymax As Double = 1 'Max value for y (in meters)

Const Pymin As Double = 0.001

Const deltay As Double = (Pymax - Pymin) / Steps 'Distance between y values

Const dadt As Double = 10 'Constant value for da/dt (m/sec/sec/sec)

Const q As Double = 1 '1-coul point charge is modeled

Const t As Double = 0 'All Ex computations occur at t=0

'Variables follow.

Dim i As Long 'Loop index

Dim Py(Steps) As Double 'Points at which Ex is computed

Dim tr As Double 'Retarded time

Dim dt As Double 't-tr

Dim dtmin As Double 'Minimum value for dt

Dim dtmax As Double 'maximum value for dt

Dim xr As Double 'Retarded position on x-axis

Dim vr As Double 'Retarded velocity

Dim ar As Double 'Retarded acceleration

Dim Drx As Double 'x-component of vector Dr

Dim Dry As Double 'y-component of vector Dr

Dim Dr As Double 'Magnitude of vector Dr

Dim ux As Double 'x-component of vector u

Dim uy As Double 'y-component of vector u

Dim Ex(Steps) As Double 'x-component of electric field vector

Dim ExTruncated(Steps) As Double 'Truncated E field (for plotting)

Dim ExAverage, ExTheoretical As Double

'Executable code follows.

'First set up the field evaluation points.

For i = 0 To Steps - 1

Py(i) = Pymin + i * deltay

Next i

'Then compute the retarded time, position, velocity and acceleration.

For i = 0 To Steps - 1

dtmin = 0

dtmax = Sqr(Py(i) ^ 2 + 10 ^ 2) / c

Do

dt = (dtmax + dtmin) / 2

tr = t - dt

xr = dadt * tr ^ 3 / 6

If Abs(c * dt - Sqr(xr ^ 2 + Py(i) ^ 2)) < 2 ^ (-30) Then Exit Do

If c * dt - Sqr(xr ^ 2 + Py(i) ^ 2) > 0 Then

dtmax = dt

Else

dtmin = dt

End If

Loop

vr = dadt * tr ^ 2 / 2

ar = dadt * tr

'Now compute the components and magnitude of the vector Dr.

Drx = -xr

Dry = Py(i)

Dr = Sqr(Drx ^ 2 + Dry ^ 2)

'Compute the components of vector u.

ux = c * Drx / Dr - vr

uy = c * Dry / Dr

'Compute the x-components of the electric field.

Ex(i) = q / (4 * pi * epsilon0) * ((Dr / (Drx * ux + Dry * uy) ^ 3) * (ux * (c ^ 2 - vr ^ 2) - Dry * uy * ar))

'(Truncate to 5 significant digits for plotting purposes)

ExTruncated(i) = (Fix(Ex(i) * 1E+19)) * 1E-19

'Repeat for every value of y.

Next i

'Average the computed values of Ex.

ExAverage = 0

For i = 0 To Steps - 1

ExAverage = ExAverage + Ex(i)

Next i

ExAverage = ExAverage / Steps

'Compute the theoretical value for Ex.

ExTheoretical = q / (6 * pi * epsilon0 * c ^ 3) * dadt

'See how well ExAverage and ExTheoretical match

MsgBox ("(Average value of Ex)/(Theoretical value for Ex) = " & ExAverage / ExTheoretical)

'Write the values of Truncated Ex out for plotting purposes.

Open "c:\winmcad\Physics\POSSect1a.prn" For Output As 1

For i = 0 To Steps - 1

Write #1, Py(i), ExTruncated(i)

Next i

Close 1

MsgBox ("Ready for plotting.")

End Sub