Fix for bug in exp function not changing sign

Fix for bug in exp function not changing sign

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

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

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

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.

I need a function that tells me on wich index in the array it differ in
sign.
Kindly Kerstin

13. Bug in exp()