-
Notifications
You must be signed in to change notification settings - Fork 1
/
atom.xml
59 lines (30 loc) · 10.5 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Hexo</title>
<link href="http://example.com/atom.xml" rel="self"/>
<link href="http://example.com/"/>
<updated>2021-09-14T12:44:31.559Z</updated>
<id>http://example.com/</id>
<author>
<name>John Doe</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title></title>
<link href="http://example.com/2021/12/26/%E6%95%B0%E5%80%BC%E7%A7%AF%E5%88%86--%E8%87%AA%E9%80%82%E5%BA%94%E8%BE%9B%E6%99%AE%E6%A3%AE%E6%B3%95/"/>
<id>http://example.com/2021/12/26/%E6%95%B0%E5%80%BC%E7%A7%AF%E5%88%86--%E8%87%AA%E9%80%82%E5%BA%94%E8%BE%9B%E6%99%AE%E6%A3%AE%E6%B3%95/</id>
<published>2021-12-26T06:59:34.216Z</published>
<updated>2021-09-14T12:44:31.559Z</updated>
<content type="html"><![CDATA[<h2 id="定积分的定义"><a href="#定积分的定义" class="headerlink" title="定积分的定义"></a>定积分的定义</h2><p>简单来说,函数 $f(x)$ 在区间 $[l,r]$ 上的定积分 $\int_{l}^{r}f(x)\mathrm{d}x$ 指的是 $f(x)$ 在区间 $[l,r]$ 中与 $x$ 轴围成的区域的面积(其中 $x$ 轴上方的部分为正值,$x$ 轴下方的部分为负值)。</p><p>很多情况下,我们需要高效,准确地求出一个积分的近似值。下面介绍的 <strong>辛普森法</strong>,就是这样一种求数值积分的方法。</p><h2 id="辛普森法"><a href="#辛普森法" class="headerlink" title="辛普森法"></a>辛普森法</h2><p>这个方法的思想是将被积区间分为若干小段,每段套用二次函数的积分公式进行计算。<br> 对于一个二次函数 $f(x)=Ax^2+Bx+C$,有:<br>$$<br>\int_l^r f(x) {\mathrm d}x = \frac{(r-l)(f(l)+f(r)+4 f(\frac{l+r}{2}))}{6}<br>$$</p><p>推导过程:<br>对于一个二次函数 $f(x)=Ax^2+Bx+C$;<br>求积分可得 $F(x)=\int_0^x f(x) {\mathrm d}x = \frac{a}{3}x^3+\frac{b}{2}x^2+cx+D$ 在这里 D 是一个常数,那么</p><p>$$<br>\begin{aligned}<br>\int_l^r f(x) {\mathrm d}x &= F(r)-F(l) \<br>&= \frac{a}{3}(r^3-l^3)+\frac{b}{2}(r^2-l^2)+c(r-l) \<br>&=(r-l)(\frac{a}{3}(l^2+r^2+lr)+\frac{b}{2}(l+r)+c) \<br>&=\frac{r-l}{6}(2al^2+2ar^2+2alr+3bl+3br+6c)\<br>&=\frac{r-l}{6}((al^2+bl+c)+(ar^2+br+c)+4(a(\frac{l+r}{2})^2+b(\frac{l+r}{2})+c)) \<br>&=\frac{r-l}{6}(f(l)+f(r)+4f(\frac{l+r}{2}))<br>\end{aligned}<br>$$<br>我们这样考虑:假如有一段图像已经很接近二次函数的话,直接带入公式求积分,得到的值精度就很高了,不需要再继续分割这一段了。</p><p>于是我们有了这样一种分割方法:每次判断当前段和二次函数的相似程度,如果足够相似的话就直接代入公式计算,否则将当前段分割成左右两段递归求解。</p><p>现在就剩下一个问题了:如果判断每一段和二次函数是否相似?</p><p>我们把当前段直接代入公式求积分,再将当前段从中点分割成两段,把这两段再直接代入公式求积分。如果当前段的积分和分割成两段后的积分之和相差很小的话,就可以认为当前段和二次函数很相似了,不用再递归分割了。</p><p>上面就是自适应辛普森法的思想。在分治判断的时候,除了判断精度是否正确,一般还要强制执行最少的迭代次数</p><blockquote><p>代码解释:<br>网上有很多板子,有的在第一个asr函数中有*15的操作,有的却没有;有的在第一个sar有eps/2操作的,有的没有。<br>这里给出一种比较正确的代码模板</p></blockquote><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> eps = <span class="number">10e-12</span>;<span class="comment">//控制精度,按题目来给</span></span><br><span class="line"><span class="function"><span class="keyword">double</span> <span class="title">f</span><span class="params">(<span class="keyword">double</span> x)</span> </span>{</span><br><span class="line"> <span class="keyword">double</span> y = <span class="comment">/*函数*/</span>;</span><br><span class="line"> <span class="keyword">return</span> y;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">double</span> <span class="title">simpson</span><span class="params">(<span class="keyword">double</span> l, <span class="keyword">double</span> r)</span> </span>{<span class="comment">//Simpson公式</span></span><br><span class="line"> <span class="keyword">double</span> mid = (l + r) / <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">return</span> (<span class="built_in">f</span>(l) + <span class="number">4</span> * <span class="built_in">f</span>(mid) + <span class="built_in">f</span>(r)) * (r - l) / <span class="number">6</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">double</span> <span class="title">asr</span><span class="params">(<span class="keyword">double</span> l, <span class="keyword">double</span> r, <span class="keyword">double</span> eps, <span class="keyword">double</span> ans)</span> </span>{</span><br><span class="line"> <span class="keyword">double</span> mid = (l + r) / <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">double</span> L = <span class="built_in">simpson</span>(l, mid), R = <span class="built_in">simpson</span>(mid, r);</span><br><span class="line"> <span class="keyword">if</span> (<span class="built_in">fabs</span>(L + R - ans) <= eps * <span class="number">15</span>) <span class="keyword">return</span> L + R + (L + R - ans) / <span class="number">15</span>; <span class="comment">//确认精度</span></span><br><span class="line"> <span class="keyword">return</span> <span class="built_in">asr</span>(l, mid, eps / <span class="number">2</span>, L) + <span class="built_in">asr</span>(mid, r, eps/ <span class="number">2</span>, R); <span class="comment">//精度不够则递归调用</span></span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">double</span> <span class="title">asr</span><span class="params">(<span class="keyword">double</span> l, <span class="keyword">double</span> r, <span class="keyword">double</span> eps)</span> </span>{</span><br><span class="line"> <span class="keyword">return</span> <span class="built_in">asr</span>(l, r, eps, <span class="built_in">simpson</span>(l, r));</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>参考文献:<a href="https://arxiv.org/pdf/1003.4629.pdf">A Review of Error Estimation in Adaptive Quadrature</a><br><img src="https://img-blog.csdnimg.cn/d0e57438c8524f4ab88b93b496b427c2.png" alt="在这里插入图片描述"></p>]]></content>
<summary type="html"><h2 id="定积分的定义"><a href="#定积分的定义" class="headerlink" title="定积分的定义"></a>定积分的定义</h2><p>简单来说,函数 $f(x)$ 在区间 $[l,r]$ 上的定积分 $\int_{l}^{r}f(x)\mat</summary>
</entry>
<entry>
<title>Hello World</title>
<link href="http://example.com/2021/12/26/hello-world/"/>
<id>http://example.com/2021/12/26/hello-world/</id>
<published>2021-12-26T05:48:31.223Z</published>
<updated>2021-12-26T05:46:24.768Z</updated>
<content type="html"><![CDATA[<p>Welcome to <a href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p><h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/writing.html">Writing</a></p><h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/server.html">Server</a></p><h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/generating.html">Generating</a></p><h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>]]></content>
<summary type="html"><p>Welcome to <a href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/">documentation</a> for</summary>
</entry>
</feed>