Fix for bug in exp function not changing sign

Fix for bug in exp function not changing sign

Post by Crai » Wed, 17 Sep 2003 13:02:18



Hi i have been doing some numerical modelling and i have found a bug
woith the exponential function. When the sign of the variable changes
the sign in the exponent remains as defined at the begining.

Example run:
x = [-1:.1:1];
y = exp(-x);

figure(1)
plot(x,y)

The exponetial continues to diverge for -x.

Does anyone know of a fix.

Cheers
Craig

 
 
 

Fix for bug in exp function not changing sign

Post by Tim Wilki » Wed, 17 Sep 2003 14:23:10


I don't see any problem with the exp function or the results given from
your code. Perhaps it is just not doing what you thought it would do!

y = exp(-x) is roughly equivalent y = 2.7183^(-x).

For x<0, -x is >0 and so 2.7183^n (n>0) is a number bigger than 1. As
n->inf, 2.7183^n ->> inf (i.e., faster), thus you should expect to see
an exponential increase in magnitude of y as x -> -inf. The converse is
true for x>0... i.e., 2.7183^(-n) (n>0) -> zero as n -> inf.

[SNIP]

Quote:> y = exp(-x);
> The exponetial continues to diverge for -x.


 
 
 

Fix for bug in exp function not changing sign

Post by Loren Shur » Wed, 17 Sep 2003 20:48:34



Quote:> Hi i have been doing some numerical modelling and i have found a bug
> woith the exponential function. When the sign of the variable changes
> the sign in the exponent remains as defined at the begining.

> Example run:
> x = [-1:.1:1];
> y = exp(-x);

> figure(1)
> plot(x,y)

> The exponetial continues to diverge for -x.

> Does anyone know of a fix.

> Cheers
> Craig

explain what you think the bug is...  When x is negative, the y value you are
evaluating is exp(abs(x)) since the - sign and the negative x negate, so your
plot should grow to the left.

--Loren

 
 
 

Fix for bug in exp function not changing sign

Post by Crai » Thu, 18 Sep 2003 08:14:47


Oops! It would seem that writing my thesis has taken its toll after
all. I appologies to you all. Loren i think you nailed what i want
being y=exp(abs(x)).

Thanks everyone who replied.