1
f(x) = (exp(x)-1)/x; 
g(x) = (exp(x)-1)/log(exp(x))

Analytically, f(x) = g(x) for all x.

When x approaches 0, both f(x) and g(x) approach 1.

% Compute y against x
for k = 1:15
    x(k) = 10^(-k);
    f(k) =(exp(x(k))-1)/x(k); 
    De(k) = log(exp(x(k)));
    g(k)= (exp(x(k))-1)/De(k);
end
% Plot y
plot(1:15,f,'r',1:15,g,'b');

However, g(x) works better than f(x). f(x) actually diverges when x approaches 0. Why is g(x) better than f(x)?

Tim
  • 35,413
  • 11
  • 95
  • 121
user1532230
  • 157
  • 1
  • 2
  • 7

1 Answers1

3

It's hard not to give the answer to this, so I'll only point to a few hints

  1. look at De... I mean really look at it. Note how as x gets smaller, De is no longer equal to x.

  2. Now look at exp(x) - 1. Notice a pattern.

  3. Ask yourself, what is eps(1), and why does it matter?

  4. In Matlab, exp(10^-16) -1 = 0. Why?

Rasman
  • 5,349
  • 1
  • 25
  • 38