1
$\begingroup$

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)}}
$\endgroup$
  • $\begingroup$ You don't have $f(r_1)$ and $f(r_2)$, only its derivatives? $\endgroup$ – Rahul Nov 22 '14 at 8:01
  • $\begingroup$ Yes,I have them too. $\endgroup$ – Abolfazl Nov 22 '14 at 8:08
  • 3
    $\begingroup$ Then 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$ – Rahul Nov 22 '14 at 9:04
  • $\begingroup$ @Rahul probably you could post that as an answer? $\endgroup$ – rhermans Nov 22 '14 at 10:34
  • $\begingroup$ Hi Abolfazl, welcome to Mma.SE, please consider taking the tour so you learn the basics of the site. Once you gain enough reputation by making good questions you will be able to vote up and down both questions and answers. When you see good ones, please vote them up by clicking the grey triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – rhermans Nov 22 '14 at 10:35
3
$\begingroup$

This will do it:

InterpolatingPolynomial[{{r1, y1, yp1, ypp1}, {r2, y2, yp2, ypp2}}, r]

InterpolatingPolynomial returns the polynomial of minimum degree that satisfies the given conditions. Since you have six conditions, you will automatically get a fifth-order polynomial.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.