Search code examples
algorithmmathintersectionconceptual

Find intersection(s) of any two functions - solving simultaneous equations


Imagine having any two functions. You need to find intersections of that functions. You definitely don't want to try all x values to check for f(x)==g(x). Normally in math, you create simultaneous equations derived from f(x)==g(x). But I see no way how to implement equations in any programing language.
So once more, what am I looking for:

  1. Conceptual algorithm to solve equations.
  2. The same for simultaneous and quadratic equations.

I believe there should be some workaround using function derivations, but I've recently learned derivation concept at school and I have no idea how to use it in this case.


Solution

  • That is a much harder problem than you would imagine. A good place to start for learning about these things is the Newton-Raphson method, which gives numerical approximations to equations of the form h(x) = 0. (When you set h(x) = g(x) - f(x), this provides solutions for the problem you are asking about.)

    Exact, algebraic solving of equations (as implemented in Mathematica, for example) are even more difficult, you basically have to recreate everything you would do in your head when solving an equation on a piece of paper.