## VB Program: Inverno - Test 4 Equation 15.24

The purpose of this document is to explain the implementation of the program: Test 4 Equation 15.24

### Test 4 Mercury 15.24

 ``` 2 2 du 2 k -1 2m 3 ---- + U = ---- + --- * u + 2 * mu dphi h^2 h^2 Equation 15.24 ``` ``` 2 2 du k -1 2m 2 ---- = ---- + U * (--- + 2 * mu -u) dphi h^2 h^2 Equation 15.24 ```
``` 1 For i = 0 To imax
2  For j = 1 To di
3    Select Case test
4    Case Is = 4
5      C2 = 2
6      k1 = (k2 - 1) / h2           ' Eq 15.24  page 196
7      u2 = u * u
8      fac31 = fac3
9      fac3 = k1 + u * (2 * m / h2 - u + C2 * m * u2)

10      If fac3 < 0 And Count = 0 Then
11          Debug.Print Count; sign1; "i"; i; "j"; j - 1; "fac3";
FUSINGX(fac31, "#.############"); " vu"; FUSINGX(vu, "#.#######");
" u"; FUSINGX(u, "#.##########"); " r"; FUSINGX(r, "###.######")
12         sign1 = sign1 * -1
13         Count = 1
14      End If
15      If sign1 = 1 Then kleur = LGreen Else kleur = Yellow
16      If Count > 0 Then
17        Count = Count + 1:
18        If Count >= maxcount Then Count = 0:
19        If sign1 = 1 Then kleur = LRed Else kleur = Black
20      End If
21      vu = sign1 * Sqr(Abs(fac3))
22      u = u + vu * ddPhi
23      r = 1 / u
24      phi = Phi00 * pi / 180 + i * dPhi + j * ddPhi

25      If Count > 0 And Count < 6 Then
26          Debug.Print Count; sign1; "i"; i; "j"; j; "fac3";
FUSINGX(fac3, "#.############"); " vu"; FUSINGX(vu, "#.#######");
" u"; FUSINGX(u, "#.##########"); " r"; FUSINGX(r, "###.######")
27      End If

28      TESTMAXR eccr

29      If t2 > 0 Then t2 = 0
30    End Select
31  next j
32   ' Display
33 next i
```
The most important difference between this version and the previous version are the two lines in red. The two lines are used to print the internal results of the program.

The following table shows the output of the program.
When you consider the results there are 6 ranges of 5 lines which describe almost the same event.

• The first 4 lines show what happens immediate after the start of the simulation. This is at a distance of roughly r = 100. The color is green.
• The next 5 lines show what happens when Mercury is at the closest distance. This is roughly at a distance of r = 54. The color changes to yellow.
• The next 5 lines show what happens when Mercury is at the fatherst distance. This is roughly at a distance r = 308. The color changes to green.
```countmax = 20
test  4 imax 10000 phi0 90 Ecc  0,7 Eps   .059 Epsx-0,1  ac 0  vu 0,00703452  u 0,01  vr
2  1 i    0 j 1 fac3 .000049489385 vu .0070348 u .0100035174 r 99.964838
3  1 i    0 j 2 fac3 .000049493595 vu .0070351 u .0100070350 r 99.929699
4  1 i    0 j 3 fac3 .000049497784 vu .0070354 u .0100105527 r 99.894583
5  1 i    0 j 4 fac3 .000049501951 vu .0070357 u .0100140706 r 99.859491
0  1 i  363 j 3 fac3 .000000000031 vu .0000056 u .0183880110 r 54.383260
2 -1 i  363 j 4 fac3-.000000000004 vu-.0000020 u .0183880100 r 54.383263
3 -1 i  363 j 5 fac3 .000000000008 vu-.0000029 u .0183880086 r 54.383268
4 -1 i  363 j 6 fac3 .000000000027 vu-.0000052 u .0183880059 r 54.383275
5 -1 i  363 j 7 fac3 .000000000060 vu-.0000078 u .0183880020 r 54.383287
0 -1 i 1037 j 0 fac3 .000000000020 vu-.0000045 u .0032452896 r308.138909
2  1 i 1037 j 1 fac3-.000000000010 vu .0000032 u .0032452912 r308.138756
3  1 i 1037 j 2 fac3 .000000000011 vu .0000034 u .0032452929 r308.138594
4  1 i 1037 j 3 fac3 .000000000034 vu .0000058 u .0032452958 r308.138314
5  1 i 1037 j 4 fac3 .000000000075 vu .0000086 u .0032453002 r308.137903
0  1 i 1710 j 7 fac3 .000000000010 vu .0000033 u .0183880115 r 54.383259
2 -1 i 1710 j 8 fac3-.000000000010 vu-.0000031 u .0183880099 r 54.383263
3 -1 i 1710 j 9 fac3 .000000000010 vu-.0000031 u .0183880083 r 54.383268
4 -1 i 1710 j X fac3 .000000000030 vu-.0000055 u .0183880056 r 54.383276
5 -1 i 1711 j 1 fac3 .000000000065 vu-.0000080 u .0183880015 r 54.383288
0 -1 i 2384 j 4 fac3 .000000000015 vu-.0000039 u .0032452895 r308.138915
2  1 i 2384 j 5 fac3-.000000000011 vu .0000033 u .0032452912 r308.138756
3  1 i 2384 j 6 fac3 .000000000011 vu .0000034 u .0032452929 r308.138594
4  1 i 2384 j 7 fac3 .000000000034 vu .0000059 u .0032452958 r308.138313
5  1 i 2384 j 8 fac3 .000000000075 vu .0000086 u .0032453002 r308.137902
0  1 i 3058 j 1 fac3 .000000000010 vu .0000033 u .0183880115 r 54.383259
2 -1 i 3058 j 2 fac3-.000000000010 vu-.0000031 u .0183880099 r 54.383263
3 -1 i 3058 j 3 fac3 .000000000010 vu-.0000031 u .0183880083 r 54.383268
4 -1 i 3058 j 4 fac3 .000000000030 vu-.0000055 u .0183880056 r 54.383276
5 -1 i 3058 j 5 fac3 .000000000065 vu-.0000080 u .0183880015 r 54.383288
```
Next let us go in more detail what the different values in each line mean.
• The first number has the value in 0,2,3,4 and 5. The purpose is a counter to define a range. In line #5 this number is zero. This line represents the shortest distance and the color is green. In line #6 this number is 2. This line is the first after the shortest distance. The distance start to increase.
• The next column represent the value sign1. In the first 5 lines sign1 is 1. In the next 5 lines sign is -1. In the next 5 lines sign is 1 etc. sign1 is calculated in program line 12 as a function of the sign of the parameter fac3.
• The next column represents the variable i. The typical values are 0, 363, 1037, 1710 etc.
• The next column represents the variable j. The value of the variable di is 10. When you consider the program there are two loops involved.
The inner loop is controlled by the variable j. The primary purpose is to calcuale the numerical solution of equation 15.24.
The outer loop is controlled by the variable i. The primary purpose is to show the numerical solution in a graphical representation.
• The next column shows the parameter fac3. This is the right side of the differential equation.
The important point it that almost always fac3 is positif, except twice during each revolution. The first time at perihelion and the second time at aphelion.
• The next column shows the parameter vu. The parameter is calculated in program line 21. In the first 5 lines vu is positif, in the next 5 lines negatif, than positif etc.
That means vu is positif when Mercury approaches and negatif when Mecury removes.
This behaviour is described by the parameter sign1.
sign1 is calculated in program line 12. The calculation describes that the sign of sign1 is reversed each time when the parameter fac is negatif.
• The next column shows the parameter u. The parameter u is calculated in program line 22. This line represent the equation: du/dphi = vu or du = vu * dphi or u(n) = u(n-1) + vu * dphi.
• The last column represents the parameter r. The parameter r is calculated in program line 23.

### Reflection of equation 15.24

Calculation of equation 15.24 it is not simple i.e. not straight forward. The same is also true for equation 15.23.
The difficulty lies in the quadratic nature of the equation. The consequences are square roots calculations and the factors involved can be negatif. To handle this issue in general is very tricky.
Equation 15.25 is much simpler and resembles Newton's law which is also very simple.

• Created:1 September 2016