|
|
Private Sub NonRadAccelQ_Click() '********** 'Compute the x-components of velocity and acceleration when 'the negative of the rad react force acting on a charge 'is zero. '********** 'Physical and mathematical constants Const c As Double = 299792000# 'Speed of light Const steps As Double = 500000 'Number of iterations Const dt As Double = 400 / steps 'Time between computations Const vxinit As Double = 0 'Initial velocity Const axinit As Double = 3000000# 'Initial acceleration Const mem As Double = 1 'Electromagnetic mass
Dim index As Long 'Loop counter Dim t(steps) As Double 'Time Dim vx(steps) As Double 'Velocity Dim ax(steps) As Double 'Acceleration Dim Fx(steps) As Double 'Force Dim daxdt As Double Dim gamma As Double Dim FxAv As Double 'Average force (to average out small numerical errors)
'Set initial velocity and acceleration. index = 0 vx(index) = vxinit ax(index) = axinit For index = 0 To steps - 1 'Compute dax/dt and use this to compute next v and a. t(index) = index * dt gamma = 1 / Sqr(1 - vx(index) ^ 2 / c ^ 2) daxdt = -3 * gamma ^ 2 * vx(index) * ax(index) ^ 2 / c ^ 2 vx(index + 1) = vx(index) + ax(index) * dt ax(index + 1) = ax(index) + daxdt * dt Next index 'Open output files for writing plot data to. Open "c:\Winmcad\Physics\POSsoln23_1vx.prn" For Output As #1 Open "c:\Winmcad\Physics\POSsoln23_1ax.prn" For Output As #2 Open "c:\Winmcad\Physics\POSsoln23_1Fx.prn" For Output As #3 'Write every tenth value of velocity and acceleration. For index = 0 To steps / 10 - 1 Write #1, t(10 * index), vx(10 * index) Write #2, t(10 * index), ax(10 * index) Next index 'Find the average force. FxAv = 0 For index = 0 To steps - 1 gamma = 1 / Sqr(1 - vx(index) ^ 2 / c ^ 2) Fx(index) = gamma ^ 3 * mem * ax(index) FxAv = FxAv + Fx(index) Next index FxAv = FxAv / steps 'If percent difference between force and average force is less than .00001, 'then the difference can be written off as a numerical error. For index = 0 To steps - 1 If Abs((Fx(index) - FxAv) / Fx(index)) < 0.00001 Then Fx(index) = FxAv Next index 'Write force. For index = 0 To steps / 10 - 1 Write #3, t(10 * index), Fx(10 * index) Next index Close MsgBox ("Ready for plotting.")
End Sub |