The Easy Way To Solve Equations In Python
thelivingpearl.com
The Easy Way To Solve Equations In Python
1–10 of 21 posts
Re: The Easy Way To Solve Equations In Python
#2Then I noticed that there was no mention at all of the various ways of using the R language with Python (RPy, etc.).
The easy way to solve equations in Python (or any other language for that matter) would be to take full advantage of the work that other bright people have done.
Re: The Easy Way To Solve Equations In Python
#3I was fairly impressed by this article until I noticed that the author was using Python 2.6. Isn't Python 2.7 the version usually used by those who aren't ready to make the leap to Python 3? Then I noticed that there was no mention at all of the various ways of using the R language with Python (RPy, etc.). The easy way to solve equations in Python (or any other language for that matter) would be to take full advantag…
Re: The Easy Way To Solve Equations In Python
#4Re: The Easy Way To Solve Equations In Python
#5See http://sympy.org/en/index.html . I've been using this for a while.
Re: The Easy Way To Solve Equations In Python
#6I was fairly impressed by this article until I noticed that the author was using Python 2.6. Isn't Python 2.7 the version usually used by those who aren't ready to make the leap to Python 3? Then I noticed that there was no mention at all of the various ways of using the R language with Python (RPy, etc.). The easy way to solve equations in Python (or any other language for that matter) would be to take full advantag…
Re: The Easy Way To Solve Equations In Python
#7I was fairly impressed by this article until I noticed that the author was using Python 2.6. Isn't Python 2.7 the version usually used by those who aren't ready to make the leap to Python 3? Then I noticed that there was no mention at all of the various ways of using the R language with Python (RPy, etc.). The easy way to solve equations in Python (or any other language for that matter) would be to take full advantag…
I think the article would better be described as "Basic methods for numerically solving equations". It gives a nice introduction to a number of those methods, and is really not Python specific as the code can easily be ported to any other language. I would view it as a way to learn the methods, rather than how to actually solve an equation in a program.
Re: The Easy Way To Solve Equations In Python
#8See http://sympy.org/en/index.html . I've been using this for a while.
Re: The Easy Way To Solve Equations In Python
#9See http://sympy.org/en/index.html . I've been using this for a while.
I've been using sympy to automate some derivative computation and I loved it. I found the evalf[1] function to be really helpful as it helps bridge the gap between the symbolic and numeric world. [1] http://docs.sympy.org/dev/modules/evalf.html
f = 'x**3+x-1'
x = 4
eval(f)
It should work fine.Re: The Easy Way To Solve Equations In Python
#10Except for the bisection method, all of these implementations take an argument specifying the number of iterations to run. In most cases, the only way to terminate in fewer iterations is by hitting an "exact" root, i.e., calculating the residual as exactly zero. This is poor practice for a number of reasons. First, in practice it's pretty rare for a method to find an exact zero. Second, once a method has converged to the numerical precision of the machine, making more iterations just wastes flops. So a much better approach is to specify a solution tolerance (as shown with the bisection method). Even better is to provide absolute and relative tolerances, and to choose those values based on either the domain requirements, or on the machine characteristics. Dennis & Schnabel's excellent "Numerical Methods for Unconstrained Optimization and Nonlinear Equations" has a good discussion on choosing convergence tolerances.
This dependence on iteration counts to terminate, by the way, is probably why the author equates low iteration counts with greater accuracy. But in fact these methods don't vary in their intrinsic accuracy, rather, they vary in their order of convergence.
Another example of poor practice is in the bisection method implementation. One generally should not bisect an interval using c = (a+b)/2, because the nature of finite-precision arithmetic means there is no guarantee that c will lie between a and b, even if the machine can represent numbers between a and b. A better approach is to ensure a < b, then to set c = a + (b-a)/2. This expression is much less subject to roundoff errors.