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%>
10%> \param[in] logLarger : The input scalar MATLAB ``real`` representing
11%> the natural logarithm of the larger value.
12%>
13%> \return
14%> ``logDiff`` : The output scalar MATLAB ``real`` containing the
15%> result of ``log(exp(logLarger) - exp(logSmaller))`` accurately.
16%>
17%> \interface{logsubexp}
18%> \code{.m}
19%>
20%> logDiff = pm.math.logsubexp(smaller, larger)
21%>
22%> \endcode
23%>
24%> \example{logsubexp}
25%> \include{lineno} example/math/logsubexp/main.m
26%> \output{logsubexp}
27%> \include{lineno} example/math/logsubexp/main.out.m
28%>
29%> \final{logsubexp}
30%>
31%> \author
32%> \JoshuaOsborne, May 21 2024, 9:45 PM, University of Texas at Arlington<br>
33%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
34%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
35function logDiff = logsubexp(logSmaller, logLarger)
36 logDiff = logLarger + log(-expm1(logSmaller - logLarger));
37end
function logsubexp(in logSmaller, in logLarger)
Return log(exp(logLarger) - exp(logSmaller)) more accurately.