1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>exp_sinh</title> 5<link rel="stylesheet" href="../../math.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Math Toolkit 2.12.0"> 8<link rel="up" href="../double_exponential.html" title="Double-exponential quadrature"> 9<link rel="prev" href="de_sinh_sinh.html" title="sinh_sinh"> 10<link rel="next" href="de_tol.html" title="Setting the Termination Condition for Integration"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="de_sinh_sinh.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../double_exponential.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="de_tol.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="math_toolkit.double_exponential.de_exp_sinh"></a><a class="link" href="de_exp_sinh.html" title="exp_sinh">exp_sinh</a> 28</h3></div></div></div> 29<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Real</span><span class="special">></span> 30<span class="keyword">class</span> <span class="identifier">exp_sinh</span> 31<span class="special">{</span> 32<span class="keyword">public</span><span class="special">:</span> 33 <span class="identifier">exp_sinh</span><span class="special">(</span><span class="identifier">size_t</span> <span class="identifier">max_refinements</span> <span class="special">=</span> <span class="number">9</span><span class="special">);</span> 34 35 <span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> 36 <span class="keyword">auto</span> <span class="identifier">integrate</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">b</span><span class="special">,</span> 37 <span class="identifier">Real</span> <span class="identifier">tol</span> <span class="special">=</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">Real</span><span class="special">>::</span><span class="identifier">epsilon</span><span class="special">()),</span> 38 <span class="identifier">Real</span><span class="special">*</span> <span class="identifier">error</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">,</span> 39 <span class="identifier">Real</span><span class="special">*</span> <span class="identifier">L1</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">,</span> 40 <span class="identifier">size_t</span><span class="special">*</span> <span class="identifier">levels</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">)-></span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">F</span><span class="special">>()(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">Real</span><span class="special">>()))</span> <span class="keyword">const</span><span class="special">;</span> 41 <span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">F</span><span class="special">></span> 42 <span class="keyword">auto</span> <span class="identifier">integrate</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">F</span> <span class="identifier">f</span><span class="special">,</span> 43 <span class="identifier">Real</span> <span class="identifier">tol</span> <span class="special">=</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">Real</span><span class="special">>::</span><span class="identifier">epsilon</span><span class="special">()),</span> 44 <span class="identifier">Real</span><span class="special">*</span> <span class="identifier">error</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">,</span> 45 <span class="identifier">Real</span><span class="special">*</span> <span class="identifier">L1</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">,</span> 46 <span class="identifier">size_t</span><span class="special">*</span> <span class="identifier">levels</span> <span class="special">=</span> <span class="keyword">nullptr</span><span class="special">)-></span><span class="keyword">decltype</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">F</span><span class="special">>()(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">Real</span><span class="special">>()))</span> <span class="keyword">const</span><span class="special">;</span> 47<span class="special">};</span> 48</pre> 49<p> 50 For half-infinite intervals, the <code class="computeroutput"><span class="identifier">exp</span><span class="special">-</span><span class="identifier">sinh</span></code> quadrature 51 is provided: 52 </p> 53<pre class="programlisting"><span class="identifier">exp_sinh</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">integrator</span><span class="special">;</span> 54<span class="keyword">auto</span> <span class="identifier">f</span> <span class="special">=</span> <span class="special">[](</span><span class="keyword">double</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">exp</span><span class="special">(-</span><span class="number">3</span><span class="special">*</span><span class="identifier">x</span><span class="special">);</span> <span class="special">};</span> 55<span class="keyword">double</span> <span class="identifier">termination</span> <span class="special">=</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">double</span><span class="special">>::</span><span class="identifier">epsilon</span><span class="special">());</span> 56<span class="keyword">double</span> <span class="identifier">error</span><span class="special">;</span> 57<span class="keyword">double</span> <span class="identifier">L1</span><span class="special">;</span> 58<span class="keyword">double</span> <span class="identifier">Q</span> <span class="special">=</span> <span class="identifier">integrator</span><span class="special">.</span><span class="identifier">integrate</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">termination</span><span class="special">,</span> <span class="special">&</span><span class="identifier">error</span><span class="special">,</span> <span class="special">&</span><span class="identifier">L1</span><span class="special">);</span> 59</pre> 60<p> 61 The native integration range of this integrator is (0, ∞), but we also support 62 /(a, ∞), (-∞, 0)/ and /(-∞, b)/ via argument transformations. 63 </p> 64<p> 65 Endpoint singularities and complex-valued integrands are supported by <code class="computeroutput"><span class="identifier">exp</span><span class="special">-</span><span class="identifier">sinh</span></code>. 66 </p> 67<p> 68 For example, the modified Bessel function K can be represented via: 69 </p> 70<div class="blockquote"><blockquote class="blockquote"><p> 71 <span class="inlinemediaobject"><img src="../../../equations/complex_bessel_k_integral.svg"></span> 72 73 </p></blockquote></div> 74<p> 75 Which we can code up as: 76 </p> 77<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Complex</span><span class="special">></span> 78<span class="identifier">Complex</span> <span class="identifier">bessel_K</span><span class="special">(</span><span class="identifier">Complex</span> <span class="identifier">alpha</span><span class="special">,</span> <span class="identifier">Complex</span> <span class="identifier">z</span><span class="special">)</span> 79<span class="special">{</span> 80 <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Complex</span><span class="special">::</span><span class="identifier">value_type</span> <span class="identifier">value_type</span><span class="special">;</span> 81 <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cosh</span><span class="special">;</span> <span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exp</span><span class="special">;</span> 82 <span class="keyword">auto</span> <span class="identifier">f</span> <span class="special">=</span> <span class="special">[&,</span> <span class="identifier">alpha</span><span class="special">,</span> <span class="identifier">z</span><span class="special">](</span><span class="identifier">value_type</span> <span class="identifier">t</span><span class="special">)</span> 83 <span class="special">{</span> 84 <span class="identifier">value_type</span> <span class="identifier">ct</span> <span class="special">=</span> <span class="identifier">cosh</span><span class="special">(</span><span class="identifier">t</span><span class="special">);</span> 85 <span class="keyword">if</span> <span class="special">(</span><span class="identifier">ct</span> <span class="special">></span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">value_type</span><span class="special">>::</span><span class="identifier">max</span><span class="special">()))</span> 86 <span class="keyword">return</span> <span class="identifier">Complex</span><span class="special">(</span><span class="number">0</span><span class="special">);</span> 87 <span class="keyword">return</span> <span class="identifier">exp</span><span class="special">(-</span><span class="identifier">z</span> <span class="special">*</span> <span class="identifier">ct</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">cosh</span><span class="special">(</span><span class="identifier">alpha</span> <span class="special">*</span> <span class="identifier">t</span><span class="special">);</span> 88 <span class="special">};</span> 89 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">quadrature</span><span class="special">::</span><span class="identifier">exp_sinh</span><span class="special"><</span><span class="identifier">value_type</span><span class="special">></span> <span class="identifier">integrator</span><span class="special">;</span> 90 <span class="keyword">return</span> <span class="identifier">integrator</span><span class="special">.</span><span class="identifier">integrate</span><span class="special">(</span><span class="identifier">f</span><span class="special">);</span> 91<span class="special">}</span> 92</pre> 93<p> 94 The only wrinkle in the above code is the need to check for large <code class="computeroutput"><span class="identifier">cosh</span><span class="special">(</span><span class="identifier">t</span><span class="special">)</span></code> in which case we assume that <code class="computeroutput"><span class="identifier">exp</span><span class="special">(-</span><span class="identifier">x</span> 95 <span class="identifier">cosh</span><span class="special">(</span><span class="identifier">t</span><span class="special">))</span></code> tends 96 to zero faster than <code class="computeroutput"><span class="identifier">cosh</span><span class="special">(</span><span class="identifier">alpha</span> <span class="identifier">x</span><span class="special">)</span></code> tends 97 to infinity and return <code class="computeroutput"><span class="number">0</span></code>. Without 98 that check we end up with <code class="computeroutput"><span class="number">0</span> <span class="special">*</span> <span class="identifier">Infinity</span></code> 99 as the result (a NaN). 100 </p> 101</div> 102<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 103<td align="left"></td> 104<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 105 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 106 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 107 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 108 Daryle Walker and Xiaogang Zhang<p> 109 Distributed under the Boost Software License, Version 1.0. (See accompanying 110 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 111 </p> 112</div></td> 113</tr></table> 114<hr> 115<div class="spirit-nav"> 116<a accesskey="p" href="de_sinh_sinh.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../double_exponential.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="de_tol.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 117</div> 118</body> 119</html> 120