Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Here is an implementation that solves the particular problem posted in the question. It uses the Shanks transformation, and a search procedure that is using the difference of consecutive results for a stopping criteria. (As in Cauchy's convergence test.) I tried the Richardson extrapolation too but it did not give good results. (Using the Shanks-vs-Richardson comparison code in this answer of minethis answer of mine.)

Here is an implementation that solves the particular problem posted in the question. It uses the Shanks transformation, and a search procedure that is using the difference of consecutive results for a stopping criteria. (As in Cauchy's convergence test.) I tried the Richardson extrapolation too but it did not give good results. (Using the Shanks-vs-Richardson comparison code in this answer of mine.)

Here is an implementation that solves the particular problem posted in the question. It uses the Shanks transformation, and a search procedure that is using the difference of consecutive results for a stopping criteria. (As in Cauchy's convergence test.) I tried the Richardson extrapolation too but it did not give good results. (Using the Shanks-vs-Richardson comparison code in this answer of mine.)

Mentioning that Richardson extrapolation did not work.
Source Link
Anton Antonov
  • 38.5k
  • 3
  • 104
  • 184

Here is an implementation that solves the particular problem posted in the question. It uses the Shanks transformation, and a search procedure that is using the difference of consecutive results for a stopping criteria. (As in Cauchy's convergence test.) I tried the Richardson extrapolation too but it did not give good results. (Using the Shanks-vs-Richardson comparison code in this answer of mine.)

Here is an implementation that solves the particular problem posted in the question. It uses the Shanks transformation, and a search procedure that is using the difference of consecutive results for a stopping criteria. (As in Cauchy's convergence test.)

Here is an implementation that solves the particular problem posted in the question. It uses the Shanks transformation, and a search procedure that is using the difference of consecutive results for a stopping criteria. (As in Cauchy's convergence test.) I tried the Richardson extrapolation too but it did not give good results. (Using the Shanks-vs-Richardson comparison code in this answer of mine.)

Better comments in the code
Source Link
Anton Antonov
  • 38.5k
  • 3
  • 104
  • 184
Clear[SearchSumValue] SearchSumValue[partialSumFunc_, accGoal_, step_: 10, startStep_: 40, methodFunc_: Shanks] := Block[{res, pf = 2}, res = NestWhile[ {#[[1]] + step, #[[3]], methodFunc[partialSumFunc, #[[1]] + step]} &, {1, methodFunc[partialSumFunc, startStep], methodFunc[partialSumFunc, startStep + step]}, Abs[N[#[[2]], pf*accGoal] - N[#[[3]], pf*accGoal]] > 10^-accGoal &]; (* n-steps, estimate, error *) Append[res[[{1, 3}]], Abs[N[res[[2]], pf*accGoal] - N[res[[3]], pf*accGoal]]] ]; 
sf[n_] := Sum[(-1)^i/i^3, {i, 1, n}] (* partialSumFunc, accGoal, step, startStep, methodFunc *) res = SearchSumValue[sf, 20, 30, 40, Shanks[#1, 6, #2] &]; N[res[[2]] - exact, 40] (* 8.757707518816394163494370352471694535835*10^-28 *)   (* partialSumFunc, accGoal, step, startStep, methodFunc *) res = SearchSumValue[sf, 50, 40, 40, Shanks[#1, 6, #2] &]; N[res[[2]] - exact, 50] (* -3.1179069154714173193769908669678269443598103298019*10^-50 *) 
Clear[SearchSumValue] SearchSumValue[partialSumFunc_, accGoal_, step_: 10, startStep_: 40, methodFunc_: Shanks] := Block[{res, pf = 2}, res = NestWhile[ {#[[1]] + step, #[[3]], methodFunc[partialSumFunc, #[[1]] + step]} &, {1, methodFunc[partialSumFunc, startStep], methodFunc[partialSumFunc, startStep + step]}, Abs[N[#[[2]], pf*accGoal] - N[#[[3]], pf*accGoal]] > 10^-accGoal &]; Append[res[[{1, 3}]], Abs[N[res[[2]], pf*accGoal] - N[res[[3]], pf*accGoal]]] ]; 
sf[n_] := Sum[(-1)^i/i^3, {i, 1, n}] res = SearchSumValue[sf, 20, 30, 40, Shanks[#1, 6, #2] &]; N[res[[2]] - exact, 40] (* 8.757707518816394163494370352471694535835*10^-28 *) res = SearchSumValue[sf, 50, 40, 40, Shanks[#1, 6, #2] &]; N[res[[2]] - exact, 50] (* -3.1179069154714173193769908669678269443598103298019*10^-50 *) 
Clear[SearchSumValue] SearchSumValue[partialSumFunc_, accGoal_, step_: 10, startStep_: 40, methodFunc_: Shanks] := Block[{res, pf = 2}, res = NestWhile[ {#[[1]] + step, #[[3]], methodFunc[partialSumFunc, #[[1]] + step]} &, {1, methodFunc[partialSumFunc, startStep], methodFunc[partialSumFunc, startStep + step]}, Abs[N[#[[2]], pf*accGoal] - N[#[[3]], pf*accGoal]] > 10^-accGoal &]; (* n-steps, estimate, error *) Append[res[[{1, 3}]], Abs[N[res[[2]], pf*accGoal] - N[res[[3]], pf*accGoal]]] ]; 
sf[n_] := Sum[(-1)^i/i^3, {i, 1, n}] (* partialSumFunc, accGoal, step, startStep, methodFunc *) res = SearchSumValue[sf, 20, 30, 40, Shanks[#1, 6, #2] &]; N[res[[2]] - exact, 40] (* 8.757707518816394163494370352471694535835*10^-28 *)   (* partialSumFunc, accGoal, step, startStep, methodFunc *) res = SearchSumValue[sf, 50, 40, 40, Shanks[#1, 6, #2] &]; N[res[[2]] - exact, 50] (* -3.1179069154714173193769908669678269443598103298019*10^-50 *) 
Source Link
Anton Antonov
  • 38.5k
  • 3
  • 104
  • 184
Loading