As many viewers will have noticed, Albert has got himself thoroughly tangled in this thread. Reading his above post demonstrates confusion of degrees with grads and angle with length. This has arisen because he does not understand the fundamental language of mathematics or the principles of numerical computation.
Once Albert got it into his head that a radius vector could be forced to a length of one, (normalised), by using a square root and a couple of divisions he insisted that it be used in his solution. This is a disaster because not only are the square root and division the slowest arithmetic operators available but they both display inherent numerical noise, noise that is not attenuated by following operations. Albert then applied the normalisation twice thereby demonstrating clearly that he had no understanding of how or why that code block worked. That was the same as assigning 1 to r, twice. r = 1 : r = 1.
Albert now finds himself in the position of wanting to fix the angle precisely so he can then normalise the radius. Neither of these processes is actually required if the sine and cosine functions are used because they will immediately give the coordinates of a point that lies on the circle. Unfortunately, one logical way to set the angle is to use the tangent function. Theoretically that use of the tangent is OK, but as a power series it does not numerically converge in a well behaved way. The tangent function is a bastard to calculate to many places unless derived by first calculating the sine or cosine. That is because it uses the somewhat erratic and difficult to compute Bernoulli numbers in it's power series. 14 year old mathematics students know that tan(x) = sin(x) / cos(x) and that the tangent function is more knotty than either sine or cosine, which is what you would expect when you divide one infinite power series by another, that's where the Bernoulli numbers come from. Albert has seen Bernoulli's 300 year old first footsteps in this field, but Albert is so far behind that he thinks he is first.
Here is the slow and inefficient code that Albert expects to discover a faster, accurate replacement for.
Code: Select all
For t = 0 To Pion2 Step Pion2 / 100
' set the exact phase angle
x = 1
y = Tan(t)
' normalize the radius
r = Sqr(x*x + y*y)
c = x / r
s = y / r
Next t
It is clear that any attempt to “peg the degrees” as Albert puts it, has an equivalent complexity to solving the tangent function. So it has just transferred the problem to more boggy ground near the top of a cliff face, the danger is realised with the final computation of Tan(Pion2) = infinity. It could have been easily avoided by sticking with the sine and cosine functions as shown here.
Code: Select all
Const As Double Pion2 = 2 * Atn(1)
Dim As Double t, r, y, c, s
' setting angle, followed by normalization
For t = 0 To Pion2 Step Pion2 / 10
y = Tan(t) ' x = 1
r = Sqr(1 + y*y)
c = 1 / r
s = y * c ' avoids the second division
Print t, c, s
Next t
Print
' using cosine and computing sine from cosine
For t = 0 To Pion2 Step Pion2 / 10
c = Cos(t)
s = Sqr(1 - c*c) ' when the root is faster than s = Sin(t)
Print t, c, s
Next t
It seems that Albert's ideas are on a mystery tour, he wants others to watch him chase an undefined and invisible wild goose. He is proud of his failures which is why he posts them on the forum. This behaviour is more like an entertaining clown or slap-stick comedian than a village bright, it is quite unlike the court jester who only plays the fool to air inconvenient truths. A stand-up comedian does not have to understand the economy to make jokes about it, likewise Albert does not need to understand mathematics, he only needs to misapply mathematics to draw the attention of others.
Albert does not take the advice he is given and does not answer the questions he is asked. If he understood the advice or answered the questions, the attention would be gone because the problem could be resolved. This explains why the goal posts keep jumping sideways, or to the other end of the field. When the problem becomes dangerously close to resolution Albert re-defines the goal to avoid a solution.
Without the focus and ability to trust in and to study mathematics, the prognosis can not be good. Unfortunately the focus needed to concentrate on the study of mathematics is countered by Albert's impulsiveness and lack of mental discipline. Any holistic approach to the solution of the mathematical problems that Albert has presented in this thread require a change in the way that Albert cerebrates before they will be resolved to his satisfaction.
So what can be learnt from Albert's unique approach.
A solid mathematical foundation is essential. It is like having a fence along the top of a cliff face to prevent naive children and the blind from walking over the edge. If you do not know where the pitfalls are, then you are in danger without fences. The young impulsively do risky things, they fall of cliffs after climbing the security fence and they drive cars into trees and lamp posts, many die, a few survive to get medals and be called heroes. Charging forwards in mathematics with no regard for reason or safety is just foolish. In mathematics you start inside a small tightly fenced region and then move the fence outwards only after you have proven that the area to be enclosed is quite safe. The heroes are those who prove and safely fence the largest areas. Dancing around outside the fence with your eyes shut is a recipe for disaster.
Computational noise is generated by floating point instructions as they are executed. For any particular floating point definition, the choice of algorithm and instruction order decides the final accumulated error. Computational time is important. Unless the programmer understands the approximate internal cycle count of every part of each expression in the program there can be no certainty of optimising any trade between speed and accuracy. Preferentially use constants rather than variables, + - * rather than divide, avoid square roots wherever possible and keep well clear of the ^ operator if you want speed. Where there is a faster way to solve a problem to the required accuracy, that faster way should be used. The required accuracy must be be explicitly specified.
A good start to function approximation is to define the function over a range of 0 to 1, or for some circular functions 0 to a rational multiple of Pi. When this is done many constants disappear and the equations simplify to their minimum computational complexity. Albert insists on writing equations with 100 “degrees” in a quadrant. This not only makes it difficult to follow the equations, but it also makes for slow code as the constant 100 repeatedly returns to increase the complexity. Addition or subtraction can lead to loss of accuracy in floating point computations. Avoid introducing things that often need to be divided by a constant or be offset by a constant before they are useful. Keep it simple unless you want to generate computational noise and appear to be stupid.
If a line looks straight when you put your ruler up against it then you can only say that the line is as bent as the ruler. You cannot say that it is a straight line unless you flip the ruler to reverse any rule curvature. Likewise, comparing good approximations of sine and cosine to the internal FB circular functions cannot tell you which is the more correct, FB or your implementation. The FB internal functions are very good approximations, correct to better than about 15 digits. If you are interested in measuring errors beyond about 13 digits you must get a better rule than the FB internal double precision functions.
When drawing to the screen you can use a ruler with half pixel bumps in it. The Nyquist–Shannon sampling theorem states that you must sample with a resolution at least twice that of the detail you are interested in. If you have 1000 pixels across the screen then you can only resolve your image to a resolution of 1 in 500 or 0.2% in position. The sampling theorem works backwards also. When drawing to the screen there is no gain in being more precise than half a pixel. For this reason graphics routines need only about 1 part in 2000 accuracy. This makes significant increases possible in graphics speed if you are prepared to find fast approximations. Most people will not notice when a circle is drawn on the screen with 60 straight lines. No ones eye will notice if you use 120 straight lines to make a circle. You cannot judge the accuracy of a circle by looking at it drawn on the screen because eyes are not calibrated. Either it looks like a circle or it does not.
Differential calculus describes the slope, the rate of change of slope, and the rate of change of the rate of change of slope, and on ad infinitum. The slope of any function is the derivative of that function. The slope of the sine function is the cosine function while the slope of the cosine function is the negative sine function. Because of this, no method of differences will simplify the approximation of sine and cosine, it will always lead back to the same problem, sine or cosine. This principle also applies to the exponential function, as Exp(x) is its own derivative.
If the derivative was a simple constant then the function would be a parabola. If the derivative was a parabola then the function would be a cubic function etc. None of these can ever exactly equal the infinite power series expansions that define the sine or cosine or exponential functions. Simple difference tables cannot therefore define sine, cosine or exponentials accurately. Each function has the characteristics of it's family. Understanding those family characteristics makes it possible to quickly implement the function. Not understanding the characteristics of the functions family will waste your effort.
Define your goal precisely. With a clear specification of what you are attempting to achieve you can tell when you have finished. It is also possible to sometimes prove that the goal is impossible to achieve. Without an aim or goal you might wander for ever in the wilderness, not knowing which way to walk and not recognising the target as you walk through it. A scientific experiment formally specifies an aim because without a known aim a rigorous discipline cannot be applied that guarantees reaching the targeted destination. Likewise mathematical software needs to be specified precisely. You are lost if you have not defined your goal.