77 lines
3.4 KiB
Plaintext
77 lines
3.4 KiB
Plaintext
Most programmers are familiar with the inexactness of floating point calculations in a binary processor.
|
|
|
|
The classic example being:
|
|
<pre>
|
|
0.1 + 0.2 = 0.30000000000000004
|
|
</pre>
|
|
|
|
In many situations the amount of error in such calculations is very small and can be overlooked or eliminated with rounding.
|
|
|
|
There are pathological problems however, where seemingly simple, straight-forward calculations are extremely sensitive to even tiny amounts of imprecision.
|
|
|
|
This task's purpose is to show how your language deals with such classes of problems.
|
|
|
|
|
|
'''A sequence that seems to converge to a wrong limit.'''
|
|
|
|
Consider the sequence:
|
|
:::::: <big><big> v<sub>1</sub> = 2 </big></big>
|
|
:::::: <big><big> v<sub>2</sub> = -4 </big></big>
|
|
:::::: <big><big> v<sub>n</sub> = 111 - 1130 / v<sub>n-1</sub> + 3000 / (v<sub>n-1</sub> * v<sub>n-2</sub>) </big></big>
|
|
|
|
|
|
As '''n''' grows larger, the series should converge to '''6''' but small amounts of error will cause it to approach '''100'''.
|
|
|
|
|
|
;Task 1:
|
|
Display the values of the sequence where n = 3, 4, 5, 6, 7, 8, 20, 30, 50 & 100 to at least '''16''' decimal places.
|
|
<pre>
|
|
n = 3 18.5
|
|
n = 4 9.378378
|
|
n = 5 7.801153
|
|
n = 6 7.154414
|
|
n = 7 6.806785
|
|
n = 8 6.5926328
|
|
n = 20 6.0435521101892689
|
|
n = 30 6.006786093031205758530554
|
|
n = 50 6.0001758466271871889456140207471954695237
|
|
n = 100 6.000000019319477929104086803403585715024350675436952458072592750856521767230266
|
|
</pre>
|
|
|
|
|
|
;Task 2:
|
|
'''The Chaotic Bank Society''' is offering a new investment account to their customers.
|
|
|
|
You first deposit $e - 1 where e is 2.7182818... the base of natural logarithms.
|
|
|
|
After each year, your account balance will be multiplied by the number of years that have passed, and $1 in service charges will be removed.
|
|
|
|
So ...
|
|
::* after 1 year, your balance will be multiplied by 1 and $1 will be removed for service charges.
|
|
::* after 2 years your balance will be doubled and $1 removed.
|
|
::* after 3 years your balance will be tripled and $1 removed.
|
|
::* <b> ... </b>
|
|
::* after 10 years, multiplied by 10 and $1 removed, and so on.
|
|
|
|
|
|
What will your balance be after 25 years?
|
|
Starting balance: $<i>e</i>-1
|
|
Balance = (Balance * year) - 1 for 25 years
|
|
Balance after 25 years: $0.0399387296732302
|
|
|
|
|
|
;Task 3, extra credit:
|
|
'''Siegfried Rump's example.''' Consider the following function, designed by Siegfried Rump in 1988.
|
|
:::::: <big><big> f(a,b) = 333.75b<sup>6</sup> + a<sup>2</sup>( 11a<sup>2</sup>b<sup>2</sup> - b<sup>6</sup> - 121b<sup>4</sup> - 2 ) + 5.5b<sup>8</sup> + a/(2b) </big></big>
|
|
:::::: <big> compute <big> f(a,b) </big> where <big> a=77617.0 </big> and <big> b=33096.0 </big></big>
|
|
:::::: <big><big> f(77617.0, 33096.0) = -0.827396059946821 </big></big>
|
|
|
|
|
|
Demonstrate how to solve at least one of the first two problems, or both, and the third if you're feeling particularly jaunty.
|
|
|
|
|
|
;See also;
|
|
* [https://perso.ens-lyon.fr/jean-michel.muller/chapitre1.pdf Floating-Point Arithmetic] Section 1.3.2 Difficult problems.
|
|
<br><br>
|
|
|