Seamlessly connect a sine curve and a parabola

I want to seamlessly connect an unknown parabola to a known sine wave. The equations are:

s(x) = a sin(bx + c)
p(x) = Ax^2 + Bx + C

I want to draw p(x) from 0 to Z and s(x) from Z to Y.

a, b, c, Z and Y are know and I want to calculate A, B and C such as s(Z) = p(Z), s'(Z) = p'(Z) and p(x) is centered on x = 0.

Somebody on StackOverflow suggested

A = ab cos(c) / (2Z)
B = 0
C = a sin(c) - A Z^2

by assuming that I wanted s(0) = p(Z) and s'(0) = p'(Z), but that didn't work for me. See the question linked above for additional information and some visualizations of the functions.

How should I calculate A, B and C?

• $\cos\bigg(\dfrac\pi2x\bigg) \simeq \bigg(1-x^2\bigg)\bigg(1-\dfrac{x^2}{4.5}\bigg)~$ for $|x|\le1$. – Lucian Dec 10 '14 at 20:57

Note that the center of a parabola is at $x=-\frac{B}{2A}$, so $B=0$.

Now solve in Mathematica and plot the result:

s[x_] := a Sin[b x + c];
p[x_] := A x^2 + C;
rule = Solve[s[Z] == p[Z] && s'[Z] == p'[Z], {A, C}][]
f[x_] := Piecewise[{{p[x] /. rule, x < Z}, {s[x], x >= Z}}];
Plot[f[x] /. {Z -> 0.8, a -> 1, b -> 15, c -> -3}, {x, 0, 2}]

$$\left\{\left\{A\to \frac{a b \cos (b Z+c)}{2 Z},C\to \frac{1}{2} (2 a \sin (b Z+c)-a b Z \cos (b Z+c))\right\}\right\}$$

(you can reuse $A$ on the $C$ calculation by doing $C\to a \sin (b Z+c)-AZ^2$).

An example plot: • This works great, thanks! – Ricardo Sanchez-Saez Dec 10 '14 at 18:21
• @RicardoSánchez-Sáez: Added a plot. – DumpsterDoofus Dec 10 '14 at 18:22
• By the way, how do you use Mathematica for solving equations like these? Using the above code, it outputs: Solve::ivar : 1 is not a valid variable. – Ricardo Sanchez-Saez Dec 10 '14 at 18:24
• @RicardoSánchez-Sáez: It sounds like you have $x$ already defined, and forgot about it. Execute Clear[x] and try again. – DumpsterDoofus Dec 10 '14 at 18:25
• @RicardoSánchez-Sáez: Solve by default returns a List (or {}) of solutions, because often equations have multiple solutions, and this preserves type-stability, which is a common practice in computer language design. However, since there is only one solution to this system of equations, this outer {...} is redundant, so [] returns the first element of this list with one element, ie, it removes the outer {}, and returns the solution. This solution is then subsequently used in the definition of the Piecewise function. – DumpsterDoofus Dec 10 '14 at 18:45

I don't have time for a detailed response, but you need to write three equations. One will define the exact location at which these curves will link up. The other will make sure the derivatives are equal at this point. The third will ensure the second derivatives equal at this point. Then you should have a "seamless" transition between these two curves.

You have three unknowns, $A, B, ~$and$~C$. You have three equations for location, derivative, and second derivative. The system of equations should be solvable.