Catastrophic cancellation with a specific function

  • Thread starter Thread starter NotEuler
  • Start date Start date
  • Tags Tags
    Function Specific
AI Thread Summary
The discussion centers on the function of two variables, xy (eax-eay)/(xeax-yeay), where a is a positive parameter. The primary concern is the issue of catastrophic cancellation that arises when x and y are large and close in value. A proposed solution involves rewriting the function to mitigate these computational problems. One suggestion is to change variables by expressing y as x plus a small perturbation, δ. This leads to a reformulated expression that remains exact up to that point, allowing for potential expansion using Taylor series for small δ. This approach aims to address the challenges posed by catastrophic cancellation in numerical computations involving closely sized variables.
NotEuler
Messages
58
Reaction score
2
I've been playing around with this function of two variables:
xy (eax-eay)/(xeax-yeay )
where a is a positive parameter.

Now, when x and y are very large and close to each other in size, this seems to easily lead to catastrophic cancellation and computational problems.

One thing that seems to help a little is to rewrite as follows:
xy (1-ea(y-x))/(x-yea(y-x) )

I haven't really had to deal with catastrophic cancellation issues in the past. I was wondering if there might be a better way to deal with the problem here?
 
Physics news on Phys.org
I have not dealt with catastrophic cancellation either but if x and y are large and close to each other, I would do a change in variables and write ##y=x+\delta## where ##\delta## is a small number. Then$$\frac{xy(e^{ax}-e^{ay})}{xe^{ax}-ye^{ay}}=\frac{e^{ax}x(x+\delta)(1-e^{a\delta}) }{e^{ax}[x-(x+\delta)e^{a\delta}]}=\frac{x(x+\delta)((1-e^{a\delta})}{x-(x+\delta)e^{a\delta}}.$$Up to this point the expression is exact. You can expand it, if you wish, in Taylor series for small ##\delta##. I don't know if this addresses your problem, but that's what I would try first.
 
Back
Top