Find maximum by local interpolation

We use Newton - Raphson formula for the first derivative, assuming we have a uniform grid and we have found a maximum on that grid. Three or five - points formulas can be used to refine the maximum estimate.

Example: N=3

FullSimplify[Solve[D[InterpolatingPolynomial[Table[{Subscript[x,i]+k h,Subscript[f,i+k]},{k,-1,1}],z],z]==0,z]]

Note the above formula is a one - step Newton - Raphson with 3 - points finite differencing stencils

FullSimplify[InterpolatingPolynomial[Table[{Subscript[x,i]+k h,Subscript[f,i+k]},{k,-1,1}],z]/.{z->((h ((Subscript[f, -1+i])-(Subscript[f, 1+i])))/(2 ((Subscript[f, -1+i])-2 (Subscript[f, i])+(Subscript[f, 1+i]))))+(Subscript[x, i])}]

Interpolating poly

CodeRule={Subscript[x,i]-> x0, z-> xmax, h-> dx};

N = 3

P3=FullSimplify[InterpolatingPolynomial[Table[{Subscript[x,i]+k h,Subscript[f,i+k]},{k,-1,1,1}],z]]

CForm[P3/.CodeRule]

N = 5

P5=FullSimplify[InterpolatingPolynomial[Table[{Subscript[x,i]+k h,Subscript[f,i+k]},{k,-2,2,1}],z]]

CForm[P5/.CodeRule]