1

I would like to fit a sinusoid to three data points using the function:

$y=A\cdot \sin(x+B)+C$

I've had a go at following the method described here but don't seem to be able to get far. My three points are arbitrary so I'm particularly interested in the comments made below the first answer.

The first step seems to be to remove C by subtracting equation 1 from 3 but this seems to leave me with a long expanded formula that I cannot rewrite into an expression for $\tan(B)$.

Eq1: $y_1=A\cdot \sin(x_1+B)+C$

Eq3: $y_3=A\cdot \sin(x_3+B)+C$

Expand Eq1: $y_1=A(\cos B\sin x_1+\sin B\cos x_1)+C$

Expand Eq3: $y_3=A(\cos B\sin x_3+\sin B\cos x_3)+C$

Subtract 1 from 3: $y_3-y_1=A(\cos B\sin x_3+\sin B\cos x_3)-A(\cos B\sin x_1+\sin B\cos x_1)$

Which if necessary could also be: $y_3-y_1=A\cos B\sin x_3+A\sin B\cos x_3-A\cos B\sin x_1-A\sin B\cos x_1$

Unfortunately, that's where I get stuck. I don't have the dexterity with trigonometric identities to go any further, so I'd be grateful for some direction.

Many thanks, Simon.

  • it is easier if the unknown B is not inside a dn funktion, so better work with y=Asin(x)+Bcos(x)+C it is easy to convert it in the end to A'sin(x+B') also it is much easier to plug in the numerical values of sin(x) and cos(x) and then evaluate the simple linear equations. – trula Jul 29 '21 at 14:33

1 Answers1

1

Employ the following system of equations:

$$ y_1 = A \sin x_1 + B \cos x_1 + C \\ y_2 = A \sin x_2 + B \cos x_2 + C \\ y_3 = A \sin x_3 + B \cos x_3 + C $$

Plugging in your $(x_i, y_i)$ points yields you a linear system of equations that you can solve with a method of your choosing (gaussian substitution for example).

Once you've found constants $A, B, C$ the solution can be converted to your desired form

$$y = A' \sin(x + B') + C'$$

by

$$ A' = \sqrt{A^2 + B^2} \\ B' = \arctan{\frac{B}{A}} \\ C' = C $$

(To see why - take a look at Wikibooks )

naslundx
  • 9,720
  • Thanks for your answer, that makes sense and worked fine. I did need to make a small adjustment by using atan2 because both B and A were negative. Using atan gave a result that was inverted, or 180 degs out of phase. Atan2 solved that. Thanks again. – Simon Aldworth Aug 02 '21 at 09:43