[erlang-questions] How to write this code better?
Jilani Khaldi
jilani@REDACTED
Tue Apr 15 09:39:44 CEST 2008
> Some are wronger than others.
> In particular, using a value for pi that doesn't agree with the
> trig functions you are using can give serious trouble.
> (Yes, I have known real, simple, programs crash because they used
> a 64-bit value for pi while the trig functions used an 80-bit value.)
Very true. I think the serious problem is when the value has the wrong
sign (due to some approximations) and not a less approximated value.
> My M.Sc. is in underwater acoustics.
Great! I know some abovewater acoustics :-), precisely inside buildings
which are really very complicated to solve them (in all senses).
> An error analysis is always appropriate.
>
> The Wikipedia article for "Declination" gives
>
> delta = (180/pi)*( 0.006918
> + 0.070257 sin( g) - 0.399912 cos( g)
> + 0.000907 sin(2g) - 0.006758 cos(2g)
> + 0.001480 sin(3g) - 0.002697 cos(3g) )
> where g = (2pi/365)(N-1)
>
> Turning that into code and running it over N = 1..365, I found the
> range of delta to be [-23.426039, 23.455569], which means that the
> checks for delta > 89.99 or < -89.99 are utterly pointless.
I took the code (written in Javascript) from this page:
http://squ1.org/wiki/Solar_Position_Calculator
I have seen that it gives roughly the same result as Shams (*) so I
didn't mind about the rest.
To write Shams I used the contents of the technical report from this page:
http://rredc.nrel.gov/solar/codesandalgorithms/spa/
> This addresses most of the issues I mentioned. The coefficients are given
> to the same precision, and the source is shown, so that it is possible to
> check them.
Ok, I will update the code. Thank you!
However, for me all this is only an exercice to learn Erlang remaining
in my domain. My real applications that I use at work (for ages) are
written in (Object) Pascal and/or in Ada (now 2005 GNAT) and they are
very mature.
I think that Erlang has the "feet short" (an italian translation) to
walk in scientific and technical applications, but long enough to do
many useful little things in this field.
Just a request. Could you joint us at
http://groups.google.com/group/erlstp
so we can discuss there?
I just have begun to write EMath, a small math module with few but
useful routines (the module already has almost all the maths you need
for reinforced concrete calculations and many other kinds of civil
engineering structural analysis!).
http://www.dotpas.org/estp/emath.erl
>> In many real world applications 89.9, 89.99 and 9.999 give the same
>> pratical results!
>
> Presumably 9.999 should have been 89.999. Anyway, you are right, because
> for this problem that range clipping never has any effect whatever. In
> fact, it is BETTER not to do that clipping, lest it disguise some error.
>>
>> See this image:
>> http://www.dotpas.org/software/shams1.jpg
>
> When I click on that I get
> Not Found
> The requested URL /software/shams1.jpg was not found on this server.
> Yaws 1.76 Server at deneb
Glad to know that my old Deneb still works well!
Sorry it is:
http://www.dotpas.org/software/shams1.png
--
***
Jilani KHALDI
http://www.dotpas.org
More information about the erlang-questions
mailing list