Fitting a sine curve given four known boundary conditions

67 Views Asked by At

I would like to be able to calculate the four parameters (A, B, C, D) for the sine curve $y=A\sin(Bt-C)+D$ given the generic boundary conditions that the value of the curve and its first derivative are known at two locations. That is to say, the four boundary conditions $y(t_1)=y_1$, $y(t_2)=y_2$, $\frac{dy}{dt}(t_1)=m_1$, and $\frac{dy}{dt}(t_2)=m_2$ are in effect, and the values $t_1, t_2, y_1, y_2, m_1, m_2$ are all known.

I have not been able to find a way to generate generic equations for A, B, C, and D. In the special cases where the target first derivative values $m_1$ and $m_2$ happen to correspond to well-known angles (such as $0$, $\sqrt{2}/2$, etc.), the problem is within my grasp. But I can't find a way to do it for the generic case.

1

There are 1 best solutions below

2
On

You are starting with the following equations: $$y_1=A\sin(Bt_1+C)+D$$ $$y_2=A\sin(Bt_2+C)+D$$ $$m_1=AB\cos(Bt_1+C)$$ $$m_2=AB\cos(Bt_2+C)$$

Assuming that none of the given values are zero or otherwise "convenient" and, in particular, assuming $y_1\neq y_2$ and that $m_1+m_2\neq 0$, then you can proceed as follows:

First work out $$\frac{y_1-y_2}{m_1+m_2}=\frac1B\tan\left(\frac B2(t_1-t_2)\right)$$ You may wish to check this for yourself, but this gives you an equation from which you can extract the value of $B$ using some numerical or iterative method.

Once you have $B$ you can get $C$ by considering $\frac{m_1}{m_2}$, rearranging and simplifying, and getting $$\tan C=\frac{m_1\cos(Bt_2)-m_2\cos(Bt_1)}{m_1\sin(Bt_2)-m_2\sin(Bt_1)}$$

This gives the value of $C$. Again you may wish to check this for yourself.

Finally, with $B$ and $C$ found and everything else known, you can use the first two equations to get $A$ and $D$ by solving simultaneously.