# solve system of non-linear implicit equations numerically I am attempting to solve for a solution of a system of two non-linear implicit equations using the following code:

x = var('x')
y = var('y')
P = [(-1,-5), (1,-5), (-5,0), (5,5)]

# Defining the function
d = sum([sqrt( (x-p)^2 + (y-p)^2 ) for p in P])
show(d)

# Differentiate with respect to x and y
eqx = d.diff(x)
eqy = d.diff(y)

# Plot both implicit curves
g1 = implicit_plot( eqx==0, (x,-10,10), (y,-10,10), color="blue" )
g2 = implicit_plot( eqy==0, (x,-10,10), (y,-10,10), color="red" )
show(g1 + g2) # note that you can clearly see an intersection of the two curves

# Solve for the solution
print("Solving...")
sol = solve([eqx==0, eqy==0], x, y) # this gets stuck or takes a long time
show(sol)


Everything runs, up to the point of the solve function, which continues to run for what appears to be indefinitely. The code show(g1 + g2) shows a graph that clearly shows there exists an intersection for both curves. I tried to use to_poly_solve=True without success. I do not mind an approximate solution, however I was unable to find a numeric solver for a system such as this (find_root afaik only works on one variable) that will work.

Does there exist a numeric solver which is capable of solving a system of this form? What other alternatives are there?

Thanks, menturi

edit retag close merge delete

Sort by » oldest newest most voted

I'm not aware of a built-in function for a vector version of Newton's method. There might be one built into scipy that you can import. But, you can implement your own as below.

F=vector([eqx,eqy])
v0=vector([-0.34,-3.9])
print v0
for i in range(0,4):

J=jacobian(F,[x,y]).subs(x==v0).subs(y==v0).n()
v0=v0-J.inverse()*F.subs(x==v0).subs(y==v0)
print v0, det(J)
F.subs(x==v0).subs(y==v0)


This gives the solution to be:

(-0.333333333333334, -3.88888888888889)

more This post is a wiki. Anyone with karma >750 is welcome to improve it.

You can try minimizing d using sage.minimize.

more