Created
May 27, 2017 07:06
-
-
Save idontgetoutmuch/c638fd0dd2a6af8b3503a8f05c89c326 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span style="">></span> <span style="color: green;">{-# OPTIONS_GHC -Wall #-}</span> | |
<span style="">></span> <span style="color: green;">{-# OPTIONS_GHC -fno-warn-name-shadowing #-}</span> | |
<span style="">></span> <span style="color: green;">{-# OPTIONS_GHC -fno-warn-type-defaults #-}</span> | |
<span style="">></span> <span style="color: green;">{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}</span> | |
<span style="">></span> <span style="color: green;">{-# OPTIONS_GHC -fno-warn-missing-methods #-}</span> | |
<span style="">></span> <span style="color: green;">{-# OPTIONS_GHC -fno-warn-orphans #-}</span> | |
<span style="">></span> | |
<span style="">></span> <span style="color: blue; font-weight: bold;">import</span> <span style="">Symplectic</span> | |
<span style="">></span> | |
<span style="">></span> <span style="">main</span> <span style="color: red;">::</span> <span style="">IO</span> <span style="">()</span> | |
<span style="">></span> <span style="">main</span> <span style="color: red;">=</span> <span style="color: blue; font-weight: bold;">do</span> | |
<span style="">></span> <span style="">putStrLn</span> <span style="">$</span> <span style="">show</span> <span style="">$</span> <span style="">reallyRunSteps'</span> <span class="hs-num">10</span> | |
</code></pre> | |
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span style="color: green;">{-# OPTIONS_GHC -Wall #-}</span> | |
<span style="color: green;">{-# OPTIONS_GHC -fno-warn-name-shadowing #-}</span> | |
<span style="color: green;">{-# OPTIONS_GHC -fno-warn-type-defaults #-}</span> | |
<span style="color: green;">{-# OPTIONS_GHC -fno-warn-unused-do-bind #-}</span> | |
<span style="color: green;">{-# OPTIONS_GHC -fno-warn-missing-methods #-}</span> | |
<span style="color: green;">{-# OPTIONS_GHC -fno-warn-orphans #-}</span> | |
<span style="color: blue; font-weight: bold;">import</span> <span style="">Symplectic</span> | |
<span style="">main</span> <span style="color: red;">::</span> <span style="">IO</span> <span style="">()</span> | |
<span style="">main</span> <span style="color: red;">=</span> <span style="color: blue; font-weight: bold;">do</span> | |
<span style="">putStrLn</span> <span style="">$</span> <span style="">show</span> <span style="">$</span> <span style="">reallyRunSteps'</span> <span class="hs-num">10</span></code></pre> | |
<div class="sourceCode"><table class="sourceCode python numberLines"><tr class="sourceCode"><td class="lineNumbers"><pre>1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
</pre></td><td class="sourceCode"><pre><code class="sourceCode python"><span class="kw">def</span> gauss(alpha,beta): | |
<span class="co">"""</span> | |
<span class="co"> Compute the Gauss nodes and weights from the recursion</span> | |
<span class="co"> coefficients associated with a set of orthogonal polynomials</span> | |
<span class="co"> Inputs:</span> | |
<span class="co"> alpha - recursion coefficients</span> | |
<span class="co"> beta - recursion coefficients</span> | |
<span class="co"> Outputs:</span> | |
<span class="co"> x - quadrature nodes</span> | |
<span class="co"> w - quadrature weights</span> | |
<span class="co"> Adapted from the MATLAB code by Walter Gautschi</span> | |
<span class="co"> http://www.cs.purdue.edu/archives/2002/wxg/codes/gauss.m</span> | |
<span class="co"> """</span> | |
<span class="im">from</span> scipy.linalg <span class="im">import</span> eig_banded | |
A <span class="op">=</span> np.vstack((np.sqrt(beta),alpha)) | |
x,V <span class="op">=</span> eig_banded(A,lower<span class="op">=</span><span class="va">False</span>) | |
w <span class="op">=</span> beta[<span class="dv">0</span>]<span class="op">*</span>sp.real(sp.power(V[<span class="dv">0</span>,:],<span class="dv">2</span>)) | |
<span class="cf">return</span> x,w</code></pre></td></tr></table></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Rao-Blackwellisation | |
% Dominic Steinitz | |
% 9th April 2017 | |
> {-# OPTIONS_GHC -Wall #-} | |
> {-# OPTIONS_GHC -fno-warn-name-shadowing #-} | |
> {-# OPTIONS_GHC -fno-warn-type-defaults #-} | |
> {-# OPTIONS_GHC -fno-warn-unused-do-bind #-} | |
> {-# OPTIONS_GHC -fno-warn-missing-methods #-} | |
> {-# OPTIONS_GHC -fno-warn-orphans #-} | |
> | |
> import Symplectic | |
> | |
> main :: IO () | |
> main = do | |
> putStrLn $ show $ reallyRunSteps' 10 | |
``` {.haskell .numberLines include="RunAccGPU.hs"} | |
{-# OPTIONS_GHC -Wall #-} | |
{-# OPTIONS_GHC -fno-warn-name-shadowing #-} | |
{-# OPTIONS_GHC -fno-warn-type-defaults #-} | |
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-} | |
{-# OPTIONS_GHC -fno-warn-missing-methods #-} | |
{-# OPTIONS_GHC -fno-warn-orphans #-} | |
import Symplectic | |
main :: IO () | |
main = do | |
putStrLn $ show $ reallyRunSteps' 10 | |
``` | |
``` {.python .numberLines} | |
def gauss(alpha,beta): | |
""" | |
Compute the Gauss nodes and weights from the recursion | |
coefficients associated with a set of orthogonal polynomials | |
Inputs: | |
alpha - recursion coefficients | |
beta - recursion coefficients | |
Outputs: | |
x - quadrature nodes | |
w - quadrature weights | |
Adapted from the MATLAB code by Walter Gautschi | |
http://www.cs.purdue.edu/archives/2002/wxg/codes/gauss.m | |
""" | |
from scipy.linalg import eig_banded | |
A = np.vstack((np.sqrt(beta),alpha)) | |
x,V = eig_banded(A,lower=False) | |
w = beta[0]*sp.real(sp.power(V[0,:],2)) | |
return x,w | |
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Library/Haskell/ghc-8.0.2/lib/BlogLiterately-0.8.4.3/bin/BlogLiterately --math=mathjax ForBrent.lhs > ForBrent.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment