Skip to content

Commit

Permalink
Properly render RK pairs in latex.
Browse files Browse the repository at this point in the history
  • Loading branch information
ketch committed Feb 12, 2015
1 parent 18bea67 commit c4ec15b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
49 changes: 44 additions & 5 deletions nodepy/runge_kutta_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,34 @@ def __str__(self):
return s


def latex(self):
"""A laTeX representation of the Butcher arrays."""
from sympy.printing import latex
s= r'\begin{align}'
s+='\n'
s+=r' \begin{array}{c|'
s+='c'*len(self)
s+='}\n'
for i in range(len(self)):
s+=latex(self.c[i])
for j in range(len(self)):
s+=' & '+latex(self.A[i,j])
s+=r'\\'
s+='\n'
s+=r'\hline'
s+='\n'
for j in range(len(self)):
s+=' & '+latex(self.b[j])
s+=r'\\' + '\n'
for j in range(len(self)):
s+=' & '+latex(self.bhat[j])
s+='\n'
s+=r'\end{array}'
s+=r'\end{align}'
s=s.replace('- -','')
return s


def __step__(self,f,t,u,dt,x=None,estimate_error=False,use_butcher=False):
"""
Take a time step on the ODE u'=f(t,u).
Expand Down Expand Up @@ -2243,7 +2271,7 @@ def loadRKM(which='All'):
"The optimal 3-stage, 3rd order SSP Runge-Kutta method",shortname='SSPRK33')

#================================================
A=np.array([[0,0,0],[one/3,0,0],[0.,2*one/3,0]])
A=np.array([[0,0,0],[one/3,0,0],[0,2*one/3,0]])
b=np.array([one/4,0,3*one/4])
RK['Heun33']=ExplicitRungeKuttaMethod(A,b,name='Heun33',
description= "Heun's 3-stage, 3rd order",shortname='Heun33')
Expand All @@ -2256,7 +2284,7 @@ def loadRKM(which='All'):

#================================================
A=np.array([[0,0,0],[-4*one/9,0,0],[7*one/6,-one/2,0]])
b=np.array([one/4,0.,3*one/4])
b=np.array([one/4,0,3*one/4])
RK['NSSP33']=ExplicitRungeKuttaMethod(A,b,name='NSSPRK33',
description= "Wang and Spiteri NSSP33",shortname='NSSPRK33')

Expand Down Expand Up @@ -2364,11 +2392,22 @@ def loadRKM(which='All'):
bhat=np.array([2479*one/34992,0*one,123*one/416,612941*one/3411720,43*one/1440,2272*one/6561,79937*one/1113912,3293*one/556956])
RK['BS5']=ExplicitRungeKuttaPair(A,b,bhat,name='Bogacki-Shampine RK5(4)8',shortname='BS5')
#================================================
A=np.array([[0,0,0,0,0,0,0,0,0,0,0,0,0],[1*one/18,0,0,0,0,0,0,0,0,0,0,0,0],[1*one/48,1*one/16,0,0,0,0,0,0,0,0,0,0,0],
[1*one/32,0,3*one/32,0,0,0,0,0,0,0,0,0,0],[5*one/16,0,-75*one/64,75*one/64,0,0,0,0,0,0,0,0,0],[3*one/80,0,0,3*one/16,3*one/20,0,0,0,0,0,0,0,0],[29443841*one/614563906,0,0,77736538*one/692538347,-28693883*one/1125000000,23124283*one/1800000000,0,0,0,0,0,0,0],[16016141*one/946692911,0,0,61564180*one/158732637,22789713*one/633445777,545815736*one/2771057229,-180193667*one/1043307555,0,0,0,0,0,0],[39632708*one/573591083,0,0,-433636366*one/683701615,-421739975*one/2616292301,100302831*one/723423059,790204164*one/839813087,800635310*one/3783071287,0,0,0,0,0],[246121993*one/1340847787,0,0,-37695042795*one/15268766246,-309121744*one/1061227803,-12992083*one/490766935,6005943493*one/2108947869,393006217*one/1396673457,123872331*one/1001029789,0,0,0,0],[-1028468189*one/846180014,0,0,8478235783*one/508512852,1311729495*one/1432422823,-10304129995*one/1701304382,-48777925059*one/3047939560,15336726248*one/1032824649,-45442868181*one/3398467696,3065993473*one/597172653,0,0,0],[185892177*one/718116043,0,0,-3185094517*one/667107341,-477755414*one/1098053517,-703635378*one/230739211,5731566787*one/1027545527,5232866602*one/850066563,-4093664535*one/808688257,3962137247*one/1805957418,65686358*one/487910083,0,0],[403863854*one/491063109,0,0,-5068492393*one/434740067,-411421997*one/543043805,652783627*one/914296604,11173962825*one/925320556,-13158990841*one/6184727034,3936647629*one/1978049680,-160528059*one/685178525,248638103*one/1413531060,0,0]])
A=np.array([[0,0,0,0,0,0,0,0,0,0,0,0,0],
[1*one/18,0,0,0,0,0,0,0,0,0,0,0,0],
[1*one/48,1*one/16,0,0,0,0,0,0,0,0,0,0,0],
[1*one/32,0,3*one/32,0,0,0,0,0,0,0,0,0,0],
[5*one/16,0,-75*one/64,75*one/64,0,0,0,0,0,0,0,0,0],
[3*one/80,0,0,3*one/16,3*one/20,0,0,0,0,0,0,0,0],
[29443841*one/614563906,0,0,77736538*one/692538347,-28693883*one/1125000000,23124283*one/1800000000,0,0,0,0,0,0,0],
[16016141*one/946692911,0,0,61564180*one/158732637,22789713*one/633445777,545815736*one/2771057229,-180193667*one/1043307555,0,0,0,0,0,0],
[39632708*one/573591083,0,0,-433636366*one/683701615,-421739975*one/2616292301,100302831*one/723423059,790204164*one/839813087,800635310*one/3783071287,0,0,0,0,0],
[246121993*one/1340847787,0,0,-37695042795*one/15268766246,-309121744*one/1061227803,-12992083*one/490766935,6005943493*one/2108947869,393006217*one/1396673457,123872331*one/1001029789,0,0,0,0],
[-1028468189*one/846180014,0,0,8478235783*one/508512852,1311729495*one/1432422823,-10304129995*one/1701304382,-48777925059*one/3047939560,15336726248*one/1032824649,-45442868181*one/3398467696,3065993473*one/597172653,0,0,0],
[185892177*one/718116043,0,0,-3185094517*one/667107341,-477755414*one/1098053517,-703635378*one/230739211,5731566787*one/1027545527,5232866602*one/850066563,-4093664535*one/808688257,3962137247*one/1805957418,65686358*one/487910083,0,0],
[403863854*one/491063109,0,0,-5068492393*one/434740067,-411421997*one/543043805,652783627*one/914296604,11173962825*one/925320556,-13158990841*one/6184727034,3936647629*one/1978049680,-160528059*one/685178525,248638103*one/1413531060,0,0]])
b=np.array([14005451*one/335480064,0,0,0,0,-59238493*one/1068277825,181606767*one/758867731,561292985*one/797845732,-1041891430*one/1371343529,760417239*one/1151165299,118820643*one/751138087,-528747749*one/2220607170,1*one/4])
bhat=np.array([13451932*one/455176623,0,0,0,0,-808719846*one/976000145,1757004468*one/5645159321,656045339*one/265891186,-3867574721*one/1518517206,465885868*one/322736535,53011238*one/667516719,2*one/45,0])
RK['DP8']=ExplicitRungeKuttaPair(A,b,bhat,name='Prince-Dormand 8(7)')
RK['DP8']=ExplicitRungeKuttaPair(A.astype('float64'),b.astype('float64'),bhat.astype('float64'),name='Prince-Dormand 8(7)')
#================================================
A=np.array([[0,0,0,0,0,0,0], [0.392382208054010,0,0,0,0,0,0],
[0.310348765296963 ,0.523846724909595 ,0,0,0,0,0],[0.114817342432177 ,0.248293597111781 ,0,0,0,0,0],
Expand Down
2 changes: 1 addition & 1 deletion numipedia/method_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript" src="file:///Users/ketch/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head>

<body class="light">
Expand Down
2 changes: 1 addition & 1 deletion numipedia/numipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def write_method_page(method,fname='test.html',template_file='method_template.ht
import matplotlib.pyplot as plt

# Plot stability region.
plot_file = method.shortname+'.pdf'
plot_file = method.shortname+'.png'
fig = method.plot_stability_region(to_file=plot_file,longtitle=False)
plt.close()

Expand Down

0 comments on commit c4ec15b

Please sign in to comment.