|
Well, whatever fancies you!
I ain't got no signature.
|
|
|
|
|
I agree
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
OR…
Why VB is better than C#.
Back in the days before GPS, and when Transit took up half the bridge on a destroyer, I navigated by sextant and Admiralty tables. After four years working in Iraq, I took a year off to go sailing, so thought I would computerise the tables function – using an HP75C (no Interwebs back then). I built a digital almanac in HP Basic, good for plus or minus 3k years, handling the Sun, Moon and GHA Aries. I had to jump through a few hoops to fit it all into 24k, but it worked admirably – worst landfall error 1/3 of a mile.
Later, I rewrote it in Classic VB and added the six navigational planets, and a star catalogue of the 57 navigational stars plus Polaris. Then I moved it into VB.net, and added a few more bells and whistles, just for the hell of it - running fixes, great circle routes etc.
I have now decided to put it into C#, and Xamarinate™ it for my Android tablet. Yesterday, I had a quick look through the code to see what gotchas might lie hidden and…
An eleven element array containing the relevant constants, and a loop:
For I = 0 to 10
X = X + array(I) * Tu^I
Next
Has now turned into
X = 0.40909280422233 _
- 0.02269378904316 * Tu _
- 0.00000751461206 * Tu * Tu _
+ 0.00969263751958 * Tu * Tu * Tu _
- 0.00024909726935 * Tu * Tu * Tu * Tu _
- 0.00121043431763 * Tu * Tu * Tu * Tu * Tu _
- 0.00018931974247 * Tu * Tu * Tu * Tu * Tu * Tu _
+ 0.00003451873409 * Tu * Tu * Tu * Tu * Tu * Tu * Tu _
+ 0.00013511757293 * Tu * Tu * Tu * Tu * Tu * Tu * Tu * Tu _
+ 0.00002807071214 * Tu * Tu * Tu * Tu * Tu * Tu * Tu * Tu * Tu _
+ 0.00001187793519 * Tu * Tu * Tu * Tu * Tu * Tu * Tu * Tu * Tu * Tu
This is just one of dozens of functions using exponentiation.
Please can I scream now?
P.S. Bonus points for identifying the function.
|
|
|
|
|
What is wrong with writing a pow() function ? Or use it from some exisiting library ?
|
|
|
|
|
pow() is a trigonometric function, and therefore rather slow - some of these functions run many times in a single calculation. I would only use it for fractional exponents, for which there is no other solution. As for using a different library, I have zero experience of Xamarin, so I am not sure how that would be handled. I am porting this code to get some idea of using Xamarin.
|
|
|
|
|
Rage wrote: What is wrong with writing a pow() function ?
Using a loop there is no need to write a pow() function:
Fac = Tu
X = array(0)
For I = 1 to 10
X = X + array(I) * Fac
Fac = Fac * Tu
Next
|
|
|
|
|
Elegant - I like it!
Now why didn't I think of that?
|
|
|
|
|
Thank you.
It is a common implementation for polynomial equations because it is much faster than using pow() .
|
|
|
|
|
No, thank you! This approach has now be stored away for future use.
Most of the stuff that I get paid for is LOB for SMEs - and you don't come across exponentiation. In any event, most clients specify VB because " My [insert relative of choice] did computers at school and can maintain it". Ha!
Just for the record, the function calculates the obliquity of the ecliptic for the given time, in radians.
Dim Tu As Double = (JulianDate - 2451545.0#) / 36525.0#
is the missing first line.
|
|
|
|
|
I must confess that I don't know much about astronomical navigation. So I would not got the first line.
I started my career (apprenticeship) in a company manufacturing yacht electronics including Gonio radio direction finders and selling LORAN-C navigators and have used those in the past sometimes. The first GPS system I ever saw was 1984 on a bridge of a brand new cargo ship. It was located in a 19" rack occupying more than 20 units.
|
|
|
|
|
In 1984 that would be the Transit system I mentioned in my first post. Despite its size, it still wasn't very good. At the very best, you got a fix every hour, but normally about every three hours. It took a long time to get a fix, and because of this it had to be interfaced to the ship's log for speed and distance traveled, and an electronic compass (or MUCH more expensive gyroscopic compass) for direction of travel. It got smaller quite quickly, and eventually became practical for the yachtsman by the end of the decade.
The Loran system, or in the UK, the Decca chain, was much better, and gave good and pretty much real-time results. However, relying on ground based stations, its range was very limited, and was no use at all out at sea. Ocean going ships still relied on the good old sextant.
True GPS became available to the public, in a restricted form, after Korean flight 007 was shot down by the Russians in 1983, courtesy of Ronald Reagan, but was nowhere like ready until 1989. The full constellation of satellites became available in 1995, and with full accuracy, courtesy of Bill Clinton in 1996, in 2000 - by which time, I am sure, the US military had something even better!
Sorry - I am a bit of a navigation geek.
|
|
|
|
|
If I read it right this part 'array(I) * Tu^I' is a constant and can be computed once...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
I have a feeling you've just experienced Osborn's Law.
|
|
|
|
|
Right. Wrong word...What I meant is that it can be computed once and used everywhere...
With 3 iterations (I'm too lazy for 10) I see something like this:
X0 = ?
X1 = X0 + A0 + Tu^0
X2 = X1 + A1 + Tu^1
X3 = X2 + A2 + Tu^2
=>
X3 = X1 + A1 + Tu^1 + A2 + Tu^2
=>
X3 = X0 + A0 + Tu^0 + A1 + Tu^1 + A2 + Tu^2
Where the part 'A0 + Tu^0 + A1 + Tu^1 + A2 + Tu^2' is a fixed value (is that better than const me think )
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
A simple ipow(X, N) function may be written that requires a maximum of 2*log2[N] multiplications (may be off-by-one), and a possible division (if N was negative). If all N are known, it is possible to optimize ipow() even further, by writing custom code for each power.
For summation of polynomials, note that there are special cases where the Horner polynomial calculation may be optimized:
Even polynomials p(x) = a0 + a2*x^2 + a4*x^4 ... ==> y = x^2; p(y) = a0 + a2*y + a4*y^2 ...
Odd polynomials p(x) = a1*x + a3*x^3 + a5*x^5 ... ==> y = x^2; q(y) = a1 + a3*y + a5*y^2 ... ; p(x) = q(y) * x
...
One advantage of the alternate forms is that they preserve mathematical identities such as p(x) == p(-x) for even polynomials, and p(x) = -p(-x) for odd polynomials.
Note that using Horner polynomial evaluation Horner's method - Wikipedia, the free encyclopedia[^] saves many multiplications - you only need a maximum of 2*(N-1) multiplications and (N-1) additions for the entire polynomial.
EDIT - corrected information about polynomial evaluation
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
modified 11-Apr-16 7:17am.
|
|
|
|
|
Thanks for the edits - after checking out the link to Wikipedia, I have finally got my head around the whole thing.
The only thing that would concern me is the potential loss of accuracy. The whole of my calculation is based on numerous polynomials, and some have already been truncated in the interests of speed.
At present, I am getting a 95% hit rate of 6" of arc, and 99% of 12" of arc when compared to results from the full rigorous approach. As 1' of arc is one Nautical mile in Longitude (or on the equator) this is acceptable, bearing in mind that I do all my sailing at latitudes of about 35° North, where the NM subtends more than 1' of Latitude. What it means is that the final positional accuracy is purely down to the skill of the sextant operator - an error of 1" of time is equivalent to 15" of arc, or 1/4 NM.
|
|
|
|
|
a great read that evoked fascinating responses, thanks. Is "Xamarinate" really trademarked ?
«The truth is a snare: you cannot have it, without being caught. You cannot have the truth in such a way that you catch it, but only in such a way that it catches you.» Soren Kierkegaard
|
|
|
|
|
BillWoodruff wrote: Is "Xamarinate" really trademarked ?
Yes, but only by me!
I was first going to use 'Xamarinade' as in soaked in Xamarin, but as this is my first venture into this technology, I thought it more appropriate to terminate the word in the way the terminator terminated things.
|
|
|
|
|
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Who's up for the CCC ?
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
I am waiting for Mr. Bihy[^]. If he doesn't then I will post one.
I ain't got no signature.
|
|
|
|
|
Ok thanks
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
Poor Rey[^]
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
May you carry me with you, always
Rules for the FOSW ![ ^]
if(this.signature != "")
{
MessageBox.Show("This is my signature: " + Environment.NewLine + signature);
}
else
{
MessageBox.Show("404-Signature not found");
}
|
|
|
|
|
"Remakes are the path to the dark side. Remakes leads to anger. Anger leads to hate. Hate leads to suffering."
Disappointed with episode 7 (4.1), don't think I'll be bothering with the rest
The whole thing's rigged to blow, touch those tanks and "boooom"!
modified 31-Aug-21 21:01pm.
|
|
|
|