I need to find the roots of a quite complicated equation and I've read that python has a set of function that can help. I tried to figure out how they work but I failed pretty bad. The examples that I saw are all quite simple instead I need to find the roots of this function:
With B and K real positive numbers. Can anyone help ?
Here are two solutions, the second is probably the simpler and more correct way of solving the problem.
The trick is that you have to get the function
f
to remember the values of K and B. One way of doing this is to make it an inner function of another function. The outer function is used to set K and B. These are in the variable scope of the inner function that is returned. This way the innerf
function can remember the values. The returned function is then simply passed on to the Newton-Raphson method, and it finds the root.A user commented that the
newton
function has anargs
argument, which can be used to pass extra arguments to the Newton-Raphson function. If the function has the form f(x, a, b, c...), then a, b, c... are extra arguments that can be given inargs
.The same solution would then look like this: