0

So I know there have been plenty of questions/answers on this topic, but I haven't been able to locate exactly what is going wrong in my attempts. I have two nonlinear function f(x,y) and g(x,y) and I am trying to solve the system

f(x,y) - g(x,y) = 0
f(x,y) + g(x,y) = c

where c is some positive constant. I have been using the snippet described in the answer to this question: How to solve a pair of nonlinear equations using Python?, but I am facing issues. If I run that snippet for my code, it returns the x and y values such that only the second equation in the system is satisfied, i.e. it returns x and y such that f(x,y) + g(x,y) = c, while for the other equation it holds that f(x,y) - g(x,y) != 0. I get the exact same issues when using the scipy.optimize.root function. I'm quite lost as to what could be causing this issue. Could it mean that there do not exist x, y such that both equations are satisfied?

Thanks in advance for any help!

1 Answers1

1

It is very possible that there is no solution. x + y = 10, x + y = 20 has no solution, for example. This isn't an issue of non-linearity; this is an issue of math. Also, it might be possible, if this can't be solved algebraically, that the first equation has f(x,y) - g(x,y) is approximately zero. If f(x,y)-g(x,y)=0.0001, would you consider this close enough?

For completeness: Check out the math, as noted by @tstanisl. If you add the equations together, you solve f(x,y)=c/2 or g(x,y)=c/2, which is easier.

asylumax
  • 781
  • 1
  • 8
  • 34
  • Thanks for the answer! I would indeed consider that close enough but the difference is way bigger than that, making me lean towards the idea that there is no solution or my initial guess is just miles off. The functions are quite cumbersome so local minima and maxima are not really excluded. – Charlie Shuffler Jun 04 '20 at 11:30
  • 1
    Since this is a function in x-y, you could plot f(x,y)-g(x,y) as a function of x and y, and see what this turns up. Sometimes, depending on the problem, this will give you an idea of what is going on. – asylumax Jun 04 '20 at 11:38
  • 1
    You could also plot f(x,y) + g(x,y) in a neighboring plot, and see what is going on there. And also [smacks self in head!], check out the math, as noted by @tstanisl. If you add the equations together, you solve f(x,y)=c/2 *or* g(x,y)=c/2, which is easier. Mathematically, you are eliminating one. You may still be in a situation where there is no solution, of course. – asylumax Jun 04 '20 at 12:10
  • Wait now I see it as well haha, so silly. I'll definitely give that a shot. Thanks for all the help. – Charlie Shuffler Jun 04 '20 at 12:16