View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
monir monir is offline
external usenet poster
 
Posts: 215
Default A Serious Round-Off Problem !!

Hello;

I've successfully followed certain guidelines on how additions &
subtractions should be done when rounding is a serious issue.
At least for now, I'm getting some consistency in the results, and will post
the entire process once it's fully verified.

Here's the latest:
Code:
SUB TEST4() 
' ... my code... 
  Factor = 'see below
  mySum = 0.0 
  FOR I = 1 TO 30000 
     mySum = mySum + A(I)*B(I)/C(I) /(Factor) 
  NEXT 
  Result = mySum *(Factor)  
' ...my code... 
END SUB
Factor
=.....1.0..........10.0........100.0........1000.0 .....5000.0.....10000.0
Result = 0.85933...0.85975....0.31101....0.11709....0.11709 ....0.11709

Factor =.....1.0........0.100........0.010........0.0010. ....0.0001
Result = 0.85933...0.85911....0.85916....0.85933....0.85933

The "make sense" result for the set of data is around the 0.11500 mark.

The remaining inconsistency, I believe, is primarily due to how the term
A*B/C is formulated, realizing the wide variation in the individual values.
Each element in the arrays A, B & C has a value in the range, say, +/- 1.E-6
to +/- 1.E+6. NO zeros.

The question is basically related to Arithmetic Precision in Multiplication
and Division. It should not be confused with which operation is performed
first and how the compiler does it, but rather how one would formulate the
expression in the first place to minimize the round-off error.

For example:
would: 1.0/C*A*B be more accurate than A*B/C ?
how about: A/C*B, or B*A/C ?
would assigning intermediate variable help: D = A*B, Result = D/C
or D = 1.0/C, E = A*B, Result = D*E
etc.


Surely, one may continue trying until a specific formulation is established
for each set of data! But this trial & error approach would be cumbersome at
best, and would be hardly described as scientific computing!

Your suggestion(s) regarding Arithmetic Precision in Multiplication and in
Division ... in VBA or FORTRAN ...would be greatly appreciated.

Regards.



"Jerry W. Lewis" wrote:

"monir" wrote:

I would very much appreciate your suggestion(s) on how to minimize this
serious round-off error.
Can one use a higher precission than DOUBLE ... either in VBA or FORTRAN ??


Sort by absolute value and sum from smallest to largest.

Jerry