Catastrophic cancellation with a specific function

  • Thread starter Thread starter NotEuler
  • Start date Start date
  • Tags Tags
    Function Specific
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
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.