# How do I combine InterpolatingPolynomial and Integrate?

I want to find a real-valued polynomial (or trig) function f[x] that

1. yields 0 at x=-a, and 1 at x=0
2. has gradient 0 at x=-a and also at x=0
3. satisfies Integrate[f[x], {x, -a, 0}] == 1/2

The first two criteria are easy:

InterpolatingPolynomial[{{-a, {0, 0}}, {0, {1, 0}}}, x]
*(a + x)^2*(1/a^2 - (2*x)/a^3)*


But how do I include the third criterion? I'm sure it's simple, but the documentation doesn't talk about integrals, only differentials.

• Does InterpolatingPolynomial[{{{-a}, 0, 0, 60 (1 - a)/a^3}, {{0}, 1, 0, 0}}, x] satisfy your needs? – J. M.'s torpor Oct 20 '18 at 13:14
• You have five conditions, so a degree-$4$ polynomial must work. Try with p[x_] = Sum[c[i] x^i, {i, 0, 4}]; and Solve[{p[-a] == 0, p[0] == 1, p'[-a] == 0, p'[0] == 0, Integrate[p[x], {x, -a, 0}] == 1/2}, {c[0], c[1], c[2], c[3], c[4]}]. – AccidentalFourierTransform Oct 20 '18 at 13:37
• Thanks to both of you. I have one further question, which I will post as a separate comment. For now: @J.M.'s answer seems to work, though I cannot quite parse out what's happening in the InterpolatingPolynomial function. Above my pay-grade, it would seem! @AccidentalFourierTransform's suggestions produces (I think, but could have misunderstood) x - ((3*(-5 + 6*a))/a^3)*x^2 - ((2*(-15 + 16*a))/a^4)*x^3 - ((15*(-1 + a))/a^5)*x^4, and this doesn't seem to fulfil the criteria for the function's values at x=-a and x=0. Both are helpful. (@J.M., I hope you retrieve your computer soon!) – Richard Burke-Ward Oct 20 '18 at 14:58
• Follow-up question: How would I add a stipulation that the function's gradient is constantly non-negative in the specified interval? (This probably applies more to @J.M.'s answer - but again, thanks to both of you.) – Richard Burke-Ward Oct 20 '18 at 15:00
• I had actually worked out the conditions in the code I supplied on pen and paper; the idea is to assign arbitrary values for the second derivatives and work out the necessary conditions from your integral. – J. M.'s torpor Oct 20 '18 at 18:27

To get this off the unanswered list: as I mentioned in the comments, the main idea is to put in symbolic third derivatives in InterpolatingPolynomial[], and see what happens when the third criterion is applied:

Integrate[InterpolatingPolynomial[{{{-a}, 0, 0, C[1]}, {{0}, 1, 0, C[2]}},
x], {x, -a, 0}] == 1/2 // Simplify
60 a + a^3 (C[1] + C[2]) == 60


This is the equation satisfied by the third derivatives. If, for instance, we arbitrarily and capriciously set C[2] to 0 (i.e. the third derivative on the right), we can solve for C[1]:

Solve[{%, C[2] == 0}, {C[1], C[2]}]
{{C[1] -> -((60 (-1 + a))/a^3), C[2] -> 0}}


This can then be plugged into the original interpolating polynomial:

InterpolatingPolynomial[{{{-a}, 0, 0, C[1]}, {{0}, 1, 0, C[2]}}, x] /. First[%] // Simplify
((a + x)^2 (a^4 - 2 a^3 x + 3 a^2 x^2 - 30 x^3 + 36 a x^3))/a^6