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 + CI 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^2by 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?
2 Answers
$\begingroup$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}][[1]]
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}]producing the answer:
$$\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:
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.
$\endgroup$