# Calculating intersection between a linear function and a cosine function

I'm trying to calculate the intersection between the two following functions:

• $y = kx + m$,
• $y = A \cos(B(x+C)) + D$.

To find the intersection I start by assuming that both of the functions have the same $y$ value when they intersect.

$$kx + m = A cos(B(x+C)) + D$$

If I simplify the expression I can get the following.

$$kx + m = A \cos(B(x+C)) + D \Longleftrightarrow (kx + m - D) / A = \cos(B(x+C))$$

But now I get stuck because I can't merge the x:es together since one will always be inside a cosine scope or inside a acosine scope. Therefore I'm asking for help on how to proceed.

• Could you post values of your choice for the different coefficients $(k, m, A, B, C, D)$ ? I should show you on your specific problem. Commented Jan 23, 2014 at 14:18

It's a nonlinear algebraic equation that is difficult (if at all possible) to solve analytically. You'd want to solve it numerically with any of the numerous methods that exist, e.g. Newton-Raphson technique. To do this you would also need to stipulate numerical values for the constants (A, B, ...) and be mindful that because of the curvature and periodicity of the cosine function there could be multiple intersections in which case the intersection you obtain is largely dependant on the starting 'guess' value you select at the outset of solving numerically.

Hope this helps.

Cheers,

Paul Safier

As Paul Safier explained, equations of this type are impossible to solve analytically. But, when you know the different constants, you can apply very simple methods for accurately computing the roots. As Paul Safier also mentioned, because of the presence of a trigonometric function, many roots can exist and it is crucial to select an appropriate starting point. This is why a preliminary look at the plot of the function is important since it reveals the number of possible roots and their approximate locations.

For illustration purposes, I used your equation with $k=2, m=3, A=4, B=5, C=6, D=7$. A loo at the plot shows that there are five roots respectively close to 0.8, 1.2, 1.9, 2.6, and 3.0.

Suppose that we search for the solution of the equation correponding to the third root. I shall be lazy and consider that my starting point (which I shall name x_old) is 2.0. So, I shall apply Newton method the iterative scheme of which being

x_new = x-old - f(x_old) / f'(x_old)

After each iteration, x_old is replaced by x_new.

Applying this, the following iterates are : 2.00000, 1.84217, 1.86729, 1.86726. For sure, you can continue iterating until you reach the desired level of accuracy.