Solve a pair of coupled nonlinear equations within certain limits
Asked Answered
H

1

0

This answer to this question works only for situations in which the desired solution to the coupled functions is not restricted to a certain range.

But what if, for example, we wanted a solution such that 0 < x < 10 and 0 < y < 10? Another way of thinking about this is, what if the coupled functions are undefined when x or y is, e.g., less than zero?

There are functions within scipy.optimize that find roots to a function within a given interval (e.g., brentq), but these work only for functions of one variable.

Why does scipy fall short of providing a root solver that works for multi-variable functions within specific ranges? How might such a solver be implemented?

Heeheebiejeebies answered 13/9, 2015 at 21:30 Comment(4)
You need a non-linear solver like Newton Raphson or BFGS. It becomes a linear algebra problem, with no solution guaranteed.Banksia
@Banksia i'd imagine no solution is guaranteed whether or not limits are given. why does constraining that the solution fall within certain limits require a whole new algorithm? why can't a scipy function like fsolve be adjusted to take limits? can you point me to a reference on this?Heeheebiejeebies
scicomp.stackexchange.com/questions/19982/…Banksia
@Banksia hmm, that doesn't answer my question, but i suppose i could ask my question on that SE site -- might be more likely to get me an answer.Heeheebiejeebies
S
0

This is algorithmically nontrivial. A future scipy version is likely to have this sort of routine.

Today, you can cast your root finding problem into a least-square problem (minimize the sum of squares of lhs), and use the master branch of the scipy Git repo.

EDIT : scipy.optimize.least_squares is available in released scipy for a long long time now (was not so in 2015 when this question was asked).

Stercoraceous answered 13/9, 2015 at 21:51 Comment(4)
it's also not at all clear to me how to cast my problem (the problem at the question i linked to) into a least-square problem or how to use the code at the pull request you linked to (whose main focus seems not to be the same as that of my question). can you give me some guidance?Heeheebiejeebies
Just like I said: consider the sum of squares of left-hand-sides of your equations. This only equals zero iff both l.h.s. are zero, and this is a minimum.Stercoraceous
ah, yeah, that makes sense. (there was a typo in your initial answer that was throwing me off.) but that doesn't answer my second question -- how would i use the code you linked to to solve this problem? (you've linked to changes to 15 different files in scipy.)Heeheebiejeebies
You'd need to clone the dev version of scipy, check out the PR I linked above, build it from source and e.g. follow the examples in the docstring of least_squares. Or wait until this is merged and released :-).Stercoraceous

© 2022 - 2024 — McMap. All rights reserved.