Search code examples
pythonmatlabnumerical-methodsequation-solving

Numerical and analytical equation solving in python or matlab


Let's suppose that I have two transcendental functions f(x, y) = 0 and g(a, b) = 0.

a and b depend on y, so if I could solve the first equation analytically for y, y = f(x), I could have the second function depending only on x and thus solving it numerically.

I prefer to use python, but if matlab is able to handle this is ok for me.

Is there a way to solve analytically trascendent functions for a variable with python/matlab? Taylor is fine too, as long as I can choose the order of approximation.


Solution

  • I tried running this through Sympy like so:

    import sympy
    
    j, k, m, x, y = sympy.symbols("j k m x y")
    eq = sympy.Eq(k * sympy.tan(y) + j * sympy.tan(sympy.asin(sympy.sin(y) / x)), m)
    eq.simplify()
    

    which turned your equation into

    Eq(m, j*sin(y)/(x*sqrt(1 - sin(y)**2/x**2)) + k*tan(y))
    

    which, after a bit more poking, gives us

    k * tan(y) + j * sin(y) / sqrt(x**2 - sin(y)**2) == m
    

    We can find an expression for x(y) like

    sympy.solve(eq, x)
    

    which returns

    [-sqrt(j**2*sin(y)**2/(k*tan(y) - m)**2 + sin(y)**2),
     sqrt(j**2*sin(y)**2/(k*tan(y) - m)**2 + sin(y)**2)]
    

    but an analytic solution for y(x) fails.