I am making a function in matlab to compute the following function:
for this function we have:
This is my implementation in matlab of the function:
function [b]= exponential(e)
%b = ?
b= (exp (e) -1)/e;
When I test the function with very small values, indeed the limit of the function is to 1, but when the number is very small (eg 1*e-20) the limit goes to zero? what is the explanation to this phenomenon?. Am I doing something wrong?.
x= 10e-1 , f (x)= 1.0517
x= 10e-5 , f (x)= 1.0000
x= 10e-10 , f (x)= 1.0000
x= 10e-20 , f (x)= 0
Description. M = min( A ) returns the minimum elements of an array. If A is a vector, then min(A) returns the minimum of A . If A is a matrix, then min(A) is a row vector containing the minimum value of each column of A .
y = range( X , dim ) returns the range along the operating dimension dim of X . For example, if X is a matrix, then range(X,2) is a column vector containing the range value of each row. y = range( X , vecdim ) returns the range over the dimensions specified in the vector vecdim .
X = zeros( n ) returns an n -by- n matrix of zeros. X = zeros( sz1,...,szN ) returns an sz1 -by-... -by- szN array of zeros where sz1,...,szN indicate the size of each dimension. For example, zeros(2,3) returns a 2-by-3 matrix.
The problem is that exp(x)
is approx 1+x
, but is being evaluated as 1
due to the 1
being indistinguishable from 1+x
in the floating point representation. There is a MATLAB function expm1(x)
(which is exp(x)-1
implemented for small x
) that avoids the problem and works well for small arguments:
>> x=1e-100;expm1(x)/x
ans =
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With