ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
logsubexp.m
Go to the documentation of this file.
1%> \brief
2%> Return ``log(exp(logLarger) - exp(logSmaller))`` more accurately.
3%>
4%> \warning
5%> The onus is on the user to ensure ``logSmaller < logLarger``.
6%>
7%> \param[in] logSmaller : The input scalar MATLAB ``real`` representing
8%> the natural logarithm of the smaller value.
9%> \param[in] logLarger : The input scalar MATLAB ``real`` representing
10%> the natural logarithm of the larger value.
11%>
12%> \return
13%> ``logDiff`` : The output scalar MATLAB ``real`` containing the
14%> result of ``log(exp(logLarger) - exp(logSmaller))`` accurately.
15%>
16%> \interface{logsubexp}
17%> \code{.m}
18%>
19%> logDiff = pm.math.logsubexp(smaller, larger)
20%>
21%> \endcode
22%>
23%> \example{logsubexp}
24%> \include{lineno} example/math/logsubexp/main.m
25%> \output{logsubexp}
26%> \include{lineno} example/math/logsubexp/main.out.m
27%>
28%> \final{logsubexp}
29%>
30%> \author
31%> \JoshuaOsborne, May 21 2024, 9:45 PM, University of Texas at Arlington<br>
32%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
33%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
34function logDiff = logsubexp(logSmaller, logLarger)
35 logDiff = logLarger + log(-expm1(logSmaller - logLarger));
36end
function logsubexp(in logSmaller, in logLarger)
Return log(exp(logLarger) - exp(logSmaller)) more accurately.