Message Boards Message Boards

0
|
8534 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Weird behaviour of the error function

Posted 11 years ago
Hello everyone, 

I am experiencing something very strange. As a result of a long calculation I obtain combination of functions of the type

Exp[-b t] Erfc(b x- t/x), where Erfc is the complimentary error function, b and t real parameters (b>0) and x some one dimensional variable.
I order to exhibit some symmetry I would like to use the identity Erfc(z)=1-Erf(z), where now Erf is the error function.

If I plot  Erfc(b x- t/x) and 1-Erf(b x- t/x) as a verication, it is clear that things work.

However, plotting Exp[-b t] ( 1-Erf(b x- t/x) ) things get crazy for t<0, where the plot shows some weird oscillatory behaviour and goes rapidly to zero. In the attached picture, the plot shows:

(Red) Exp[-b t] Erfc(b x- t/x)

(Black)  Exp[-b t] ( 1 - Erf(b x- t/x) ) 
 
So I am kind of puzled here ... am I doing something trivially wrong or is it a bug of Mathematica ?

Any help is more than welcome

Thanks
Attachments:
POSTED BY: Mirco Milletarì
2 Replies
Notice that the oscillations are of the order 10^-15. Whenever you have weird results from a graph, make sure to check the scale.
POSTED BY: Patrick Stevens
This is caused by the limited accuracy of floating point numbers. It happens in every programmig language on every computer that uses floating point numbers - which is basically all of them. You can read more about floating point numbers and problems like the one you are seeing online. There are many ways of working around this. The simplest is to redefine your function so that it doesn't return such small values, which are prone to problems with floating point numbers. You may also consider using the WorkingPrecision option in Plot to work with a higher precision when doing the calculations. 

If you'd still like help, what is the equation you plotted that did this? 
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract