I am trying to fit a polynomial for switch cutoff which is used in Molecular dynamics. I want a fifth order polynomial with six coefficient $c_0, ...,c_6$ between $r_1<r<r_2$ with these conditions: I have $r_1,f(r_1), f'(r_1), f''(r_1), r_2,f(r_2), f'(r_2)$ and $f''(r_2)$.
I think I should use Interpolating
but how should I say it the order of polynomial. Do you have any idea?
Is it true?
Evaluate[InterpolatingPolynomial[{{r1, yp1, ypp1}, {r2, yp2, ypp2}},r]]
Edit:
Actually I need a polynomial in power series form with 6 constant. So I think this form is better:
P[r_] := a0 + a1 r + a2 r^2 + a3 r^3 + a4 r^4 + a5 r^5
Pd[r_] := D[P[r], r];
Pdd[r_] := D[P[r], {r, 2}];
sol = Solve[{P[r1] == V, Pd[r1] == Vd, Pdd[r1] == Vdd, P[r2] == 0,
Pd[r2] == 0, Pdd[r2] == 0}, {a0, a1, a2, a3, a4, a5}] //
FullSimplify
Where $V=f(r_1), Vd=f'(r_1)$ and $Vdd=f''(r_1)$.
{{a0 -> (r2^3 (-2 (10 r1^2 - 5 r1 r2 + r2^2) V +
2 r1 (4 r1^2 - 5 r1 r2 + r2^2) Vd - r1^2 (r1 - r2)^2 Vdd))/(
2 (r1 - r2)^5),
a1 -> (r2^2 (60 r1^2 V - 2 (r1 - r2) (6 r1 - r2) (2 r1 + r2) Vd +
r1 (r1 - r2)^2 (3 r1 + 2 r2) Vdd))/(2 (r1 - r2)^5),
a2 -> (12 r1 r2 (-5 (r1 + r2) V + (r1 - r2) (2 r1 +
3 r2) Vd) - (r1 - r2)^2 r2 (3 r1^2 + 6 r1 r2 + r2^2) Vdd)/(
2 (r1 - r2)^5),
a3 -> (20 (r1^2 + 4 r1 r2 + r2^2) V -
4 (r1 - r2) (2 r1^2 + 10 r1 r2 + 3 r2^2) Vd + (r1 - r2)^2 (r1^2 +
6 r1 r2 + 3 r2^2) Vdd)/(2 (r1 - r2)^5),
a4 -> -((30 (r1 + r2) V -
2 (r1 - r2) (7 r1 + 8 r2) Vd + (r1 - r2)^2 (2 r1 + 3 r2) Vdd)/(
2 (r1 - r2)^5)),
a5 -> (12 V + (r1 - r2) (-6 Vd + (r1 - r2) Vdd))/(2 (r1 - r2)^5)}}
InterpolatingPolynomial[{{r1, y1, yp1, ypp1}, {r2, y2, yp2, ypp2}}, r]
will do it. It returns the polynomial of minimum degree that satisfies the conditions, and since you have six conditions, you will automatically get a fifth-order polynomial. $\endgroup$