precision problem from CLF

6 views
Skip to first unread message

e p chandler

unread,
Mar 22, 2011, 8:50:30 PM3/22/11
to Fortran
Could someone briefly explain what Aris did to convert Daniel's
original program that suffered from major loss of significant digits
due to cancellation into a program that worked even in single
precision?

I'm mostly curious about what principle could be cited to exaplain the
improved program. IMO, these two programs make a good teaching case.

-- Elliot



Terence

unread,
Mar 24, 2011, 10:29:09 PM3/24/11
to Fortran
Elliot, you didn't leave any clues as to what previous posting you are
referring ("Daniel's original program"). There haven't been many
postings this year at all!
Have you got the correct Fortran_ Forum?

e p chandler

unread,
Mar 29, 2011, 10:42:23 PM3/29/11
to Fortran
The original thread appeared in comp.lang.fortran, not here.

For some reason I decided to ask here instead. This was a problem of a
small particle hitting a large particle and then calculating how much
energy was lost in the collision. The original program had big
problems with numerical instability owing to the subtraction of nearly
equal quantities. The problem was reformulated by several people, the
last version posted did suffer from this problem. While this may be
more of a general programing problem than a Fortran problem, IMO we
see enough FAQs about non-language specific numerical problems that I
think it would be a good idea to handle these topics either here or in
CLF. Why? Because I would like to encourage the use of Fortran for
numeric computation. So some "off topic" material is actually
relevant, again IMO.

I also think that some general problem solving techniques are also
somewhat relevant to CLF. After all CLF is NOT comp.lang.c!

I understand more about this problem as a programming exercise than I
know about the physics. I was curious as to what physical principles
allowed the reformulation into a program that actually gave reasonable
results in single precision. Was it some conservation principle?

I also found the multiplier sin^2(theta) / (1 + cos (theta)) to be
interesting. It's an expansion of 1-cos(theta). I would have thought
of the half angle formula 2 sin^2(theta/2) first.

Elliot

Terence

unread,
Mar 29, 2011, 11:00:36 PM3/29/11
to Fortran
Rule 1 in precision programming:
Never subtract two large numbers in obtaining a data item.
(Always formulate the program to operate in terms of small changes to
a current value, and check for chaotic behaviour where possible. E.g.
related three-body problem).
Reply all
Reply to author
Forward
0 new messages