3
$\begingroup$

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

Solve[f[0] == 0 && Derivative[1][f][0] == 1/2 && f[10] == 5 && 
Derivative[1][f][10] == 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?

$\endgroup$
8
$\begingroup$

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] == 0, f'[0] == 1/2, f[10] == 5, f'[10] == 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'[0] - 1/2, f[10] - 5, f'[10] - 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.

$\endgroup$
  • 2
    $\begingroup$ You can use InterpolatingPolynomial[] directly: InterpolatingPolynomial[{{{0}, 0, 1/2}, {{10}, 5, 2/5}}, x] $\endgroup$ – J. M. will be back soon Oct 14 '18 at 17:13
  • $\begingroup$ Great. One follow-up question: is there a trigonometric equivalent to InterpolatingPolynomial? $\endgroup$ – Richard Burke-Ward Oct 14 '18 at 19:24
  • $\begingroup$ @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. $\endgroup$ – eyorble Oct 14 '18 at 19:32
  • 2
    $\begingroup$ 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. $\endgroup$ – J. M. will be back soon Oct 14 '18 at 19:40
  • $\begingroup$ Many thanks to both of you. I'll mark as answered :-) $\endgroup$ – Richard Burke-Ward Oct 14 '18 at 19:42
5
$\begingroup$

Another alternative, giving the same result is

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

(*{{f -> Function[{x}, (500 x + 10 x^2 - x^3)/1000]}}*)
$\endgroup$
  • 1
    $\begingroup$ Even more generally, DSolve[{f''''[x] == g''''[x], f[0] == 0, Derivative[1][f][0] == 1/2, f[10] == 5, Derivative[1][f][10] == 2/5}, f, x] gives a solution valid for any sufficiently smooth function g. (+1) $\endgroup$ – Michael E2 Oct 14 '18 at 22:36

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.