Simpson Iteration

124 days ago by wires

  • We are integrating a function f over an interval [a,b],
  • we need the maximum m of the fourth derivative of f in that interval \max_{\xi \in [a,b]} {\left| f^{(4)}( \xi )\right|},
  • eps is the precision
def h4(d): (a,b,M,eps) = d return 180*eps / (M*(b-a)) def h(d): return sqrt(sqrt(h4(d))) def N(d): (a,b,M,eps) = d return (b-a) / h(d) def eps(h4, a, b, M): return h4 * (b-a) * M / 180 
       

Tabulation of some calculations

def row(a,b,M,e): d = (a,b,M,e) if not eps(h4(d),a,b,M) == e: print "this shouldn't happen" return (e, float(h4(d)), float(h(d)), float(N(d)), ceil(N(d))) def table(a,b,M,es): rows = [("eps", "h^4","h","N","ceil(N)")] rows += map(lambda e: row(a,b,M,e), es) return rows 
       

HTML <table> rendering of tabular data

# surround list elements with tags and return single string def tagmap(tag, xs): return ''.join(map(lambda s: "<%s>%s</%s>"%(tag,s,tag), xs)) # build table from rows, with first row as table headers def htmltable(rows): t = [""" <style>table.my, table.my td, table.my th { border: 1px solid gray; border-collapse: collapse; padding: 6px; }</style> <table class='my'>"""] t.append("<tr>%s</tr>" % tagmap("th", rows[0])) for r in rows[1:]: t.append("<tr>%s</tr>" % tagmap("td", r)) t.append("</table>") return html('\n'.join(t)) 
       
epsilons = map(lambda i: 1/(10**i), range(12)) htmltable(table(0,1,100,epsilons)) 
       


epsh^4hNceil(N)
11.81.158292185290.863340021371
1/100.180.6513555624331.535259783872
1/1000.0180.3662841501482.730120862713
1/10000.00180.2059767143914.854917717075
1/100000.000180.1158292185298.63340021379
1/1000001.8e-050.065135556243315.352597838716
1/10000001.8e-060.036628415014827.301208627128
1/100000001.8e-070.020597671439148.549177170749
1/1000000001.8e-080.011582921852986.33400213787
1/10000000001.8e-090.00651355562433153.525978387154
1/100000000001.8e-100.00366284150148273.012086271274
1/1000000000001.8e-110.00205976714391485.491771707486


epsh^4hNceil(N)
11.81.158292185290.863340021371
1/100.180.6513555624331.535259783872
1/1000.0180.3662841501482.730120862713
1/10000.00180.2059767143914.854917717075
1/100000.000180.1158292185298.63340021379
1/1000001.8e-050.065135556243315.352597838716
1/10000001.8e-060.036628415014827.301208627128
1/100000001.8e-070.020597671439148.549177170749
1/1000000001.8e-080.011582921852986.33400213787
1/10000000001.8e-090.00651355562433153.525978387154
1/100000000001.8e-100.00366284150148273.012086271274
1/1000000000001.8e-110.00205976714391485.491771707486
htmltable(table(0,1,10,epsilons)) 
       


epsh^4hNceil(N)
118.02.059767143910.4854917717071
1/101.81.158292185290.863340021371
1/1000.180.6513555624331.535259783872
1/10000.0180.3662841501482.730120862713
1/100000.00180.2059767143914.854917717075
1/1000000.000180.1158292185298.63340021379
1/10000001.8e-050.065135556243315.352597838716
1/100000001.8e-060.036628415014827.301208627128
1/1000000001.8e-070.020597671439148.549177170749
1/10000000001.8e-080.011582921852986.33400213787
1/100000000001.8e-090.00651355562433153.525978387154
1/1000000000001.8e-100.00366284150148273.012086271274


epsh^4hNceil(N)
118.02.059767143910.4854917717071
1/101.81.158292185290.863340021371
1/1000.180.6513555624331.535259783872
1/10000.0180.3662841501482.730120862713
1/100000.00180.2059767143914.854917717075
1/1000000.000180.1158292185298.63340021379
1/10000001.8e-050.065135556243315.352597838716
1/100000001.8e-060.036628415014827.301208627128
1/1000000001.8e-070.020597671439148.549177170749
1/10000000001.8e-080.011582921852986.33400213787
1/100000000001.8e-090.00651355562433153.525978387154
1/1000000000001.8e-100.00366284150148273.012086271274
htmltable(table(0,1,1,epsilons)) 
       


epsh^4hNceil(N)
1180.03.662841501480.2730120862711
1/1018.02.059767143910.4854917717071
1/1001.81.158292185290.863340021371
1/10000.180.6513555624331.535259783872
1/100000.0180.3662841501482.730120862713
1/1000000.00180.2059767143914.854917717075
1/10000000.000180.1158292185298.63340021379
1/100000001.8e-050.065135556243315.352597838716
1/1000000001.8e-060.036628415014827.301208627128
1/10000000001.8e-070.020597671439148.549177170749
1/100000000001.8e-080.011582921852986.33400213787
1/1000000000001.8e-090.00651355562433153.525978387154


epsh^4hNceil(N)
1180.03.662841501480.2730120862711
1/1018.02.059767143910.4854917717071
1/1001.81.158292185290.863340021371
1/10000.180.6513555624331.535259783872
1/100000.0180.3662841501482.730120862713
1/1000000.00180.2059767143914.854917717075
1/10000000.000180.1158292185298.63340021379
1/100000001.8e-050.065135556243315.352597838716
1/1000000001.8e-060.036628415014827.301208627128
1/10000000001.8e-070.020597671439148.549177170749
1/100000000001.8e-080.011582921852986.33400213787
1/1000000000001.8e-090.00651355562433153.525978387154