Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calculating a function in matlab with very small values

I am making a function in matlab to compute the following function:

enter image description here

for this function we have:

enter image description here

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
like image 867
franvergara66 Avatar asked Apr 04 '12 00:04

franvergara66


People also ask

How do you find the lowest number in Matlab?

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 .

How do you find the range of a number in Matlab?

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 .

How do I generate zeros and ones in Matlab?

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.


1 Answers

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
like image 65
Ramashalanka Avatar answered Oct 26 '22 13:10

Ramashalanka