How to solve a pair of nonlinear equations using Python?


What’s the (best) way to solve a pair of non linear equations using Python. (Numpy, Scipy or Sympy)


  • x+y^2 = 4
  • e^x+ xy = 3

A code snippet which solves the above pair will be great


for numerical solution, you can use fsolve:

from scipy.optimize import fsolve
import math

def equations(p):
    x, y = p
    return (x+y**2-4, math.exp(x) + x*y - 3)

x, y =  fsolve(equations, (1, 1))

print equations((x, y))

Answered By – HYRY

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published