# How do I find a function to fit these criteria?

I want to find a smooth continuous function f[x] that satisfies the following for real values of x:

Solve[f == 0 && Derivative[f] == 1/2 && f == 5 &&
Derivative[f] == 2/5, f]


This produces {{}}, meaning no solutions. But I find this very hard to believe. Some form of sinusoidal curve would surely do the job. Which leads me to believe I am doing something wrong - presumably I'm just not creating the right input and Solve is not the right tool.

How do I find a continuous function of x that fits these criteria?

The simplest solution is probably the polynomial one. This satisfies smooth and continuous automatically. You have 4 conditions you want to satisfy, so use a cubic equation (4 parameters).

f[x_] := a x^3 + b x^2 + c x + d;
Solve[{f == 0, f' == 1/2, f == 5, f' == 2/5}, {a, b, c, d}]


{{a -> -(1/1000), b -> 1/100, c -> 1/2, d -> 0}}

Note, however, that this a singular instance of a function meeting these parameters. The reason Solve fails is because there are an infinite number of such functions, many of which cannot be reasonably represented in terms of algebraic manipulations. After all, all that has been defined here is the values at two points and the slopes at two points. So long as whatever happens in-between is smooth and continuous, anything can happen.

J.M. has noted that this process has been implemented in Mathematica already as InterpolatingPolynomial:

InterpolatingPolynomial[{{{0}, 0, 1/2}, {{10}, 5, 2/5}}, x]


To extend this process to alternative forms, just pick an appropriate f. For example, to fit this with a pair of sine curves, the following suffices:

f[x_] := a Sin[b x] + c Sin[x];
NMinimize[Norm[{f' - 1/2, f - 5, f' - 2/5}], {a, b, c}]


NMinimize is used here because the exact solvers seem to have a fair bit of difficulty with this form. The result is reasonably accurate even without fine-tuning. Since there is a zero at the origin and that this function is guaranteed zero at the origin, including that criteria would only confuse the solver in this case and a parameter can be omitted.

• You can use InterpolatingPolynomial[] directly: InterpolatingPolynomial[{{{0}, 0, 1/2}, {{10}, 5, 2/5}}, x] – J. M. will be back soon Oct 14 '18 at 17:13
• Great. One follow-up question: is there a trigonometric equivalent to InterpolatingPolynomial? – Richard Burke-Ward Oct 14 '18 at 19:24
• @RichardBurke-Ward As far as I am aware, there is no equivalent function defined in Mathematica for trigonometric functions. While there certainly do exist a pair of sine waves that'll match those derivatives and positions, it's rather less clear how to go about finding their parameters. Choosing an appropriate f is the first step, but subsequently solving it is more difficult. Since there's a zero at the origin, I'd suggest f[x_] := a Sin[b x] + c Sin[d x] as a starting point. – eyorble Oct 14 '18 at 19:32
• Altho there are equivalents of Lagrange and Hermite interpolation for trigonometric interpolants, the algorithms are not built-in.@Richard, those will need to be implemented manually if you really need them. – J. M. will be back soon Oct 14 '18 at 19:40
• Many thanks to both of you. I'll mark as answered :-) – Richard Burke-Ward Oct 14 '18 at 19:42

Another alternative, giving the same result is

DSolve[f''''[x] == 0 && f == 0 && Derivative[f] == 1/2 &&
f == 5 && Derivative[f] == 2/5, f, x]

(*{{f -> Function[{x}, (500 x + 10 x^2 - x^3)/1000]}}*)

• Even more generally, DSolve[{f''''[x] == g''''[x], f == 0, Derivative[f] == 1/2, f == 5, Derivative[f] == 2/5}, f, x] gives a solution valid for any sufficiently smooth function g. (+1) – Michael E2 Oct 14 '18 at 22:36