![]() ![]() If you supply a lambda that computes y, you can provide a general solution thus: def inverse(f, f_prime=None): In the example, you can cast the problem as looking for a root of the function f( x) = x² - y. It finds roots of an equation, i.e., values of x for which f( x) = 0. If all this was to get a quick and dirty solutions to equations then there is always Wolfram Alpha. Make sure to read the Gotchas and Pitfalls section of the SymPy documentation on how to encode the appropriate equations. Not nearly as nice as Mathematica, but then again, it is free and you can incorporate it into your own programs. > equation = Eq(x ** 2, y) # create the equationĪs you see the basics are fairly workable, even as an interactive algebra system. > y = Symbol("y") # create the two variables You will need to make sure that SymPy package is installed, then: > from sympy import * # we are importing everything for ease of use Here is an example using the Python interpreter to solve the equation that is mentioned in the question. The whole SymPy package is directed at doing symbolic manipulation. For something simple, the newton is a pretty good start for simple polynomials, but you can take it from there.įor symbolic solutions (which is to say to get y = x**2 -> x = +/- sqrt(y)) SymPy solver gives you roughly what you need. ![]() just interested in the numbers, not the symbolic closed form solutions), then there are a few options for you in the SciPy.optimize module. If you are looking for numerical solutions (i.e. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |