I have some values which are close to zero (such as e^(-800) ) , and when i run my code, MATLAB rounds off these values to zero.How to prevent this from happening
Past the epsilon of the datatype, it becomes an approximation. It's approximately zero. Also, the path to zero probably has some very large errors at the end. Matlab seems to have arbitrary-precision support in their Symbolic Math Toolbox.
Past the epsilon of the datatype, it becomes an approximation. It's approximately zero. Also, the path to zero probably has some very large errors at the end. Matlab seems to have arbitrary-precision support in their Symbolic Math Toolbox.
Bjorn is totally right. If all your values are in that range you can just multiply them by 1e800 to prevent the rounding. Otherwise, if the values you are interested in are somewhere near 1 or higher do you really think that it matters if the value is 0 or 1e-800? So, I would advice to normalize your values to one. In any case, if you compute numeric values there is always a limit on the number of digits that are correctly reproduced.
Bjorn is right and when it comes to number crunching, what Sascha has written makes sense. However, you can use variable precision accuracy while doing symbolic computation. Take a look at the following:
Since you are in Electrical Engineering, I wonder if you are perhaps performing a calculation something like y = x - W(exp(x)) where W() is the Lambert W function ?
If so, then I can suggest an alternative formula (procedure) which will possibly avoid the underflow in your calculation.
ok, good. Then see Arxiv 1504.01964 for a procedure, which calculates y directly, without going through the intermediate calculation of exp(x). It is described in the Arxiv note as being the solution of y = log(W(exp(x))) but it is mathematically equivalent to y = x - W(exp(x)). And the algorithm does not require calculation of exp(x) intermediate. Please let me know if you have trouble implementing in Matlab.