Ask Your Question
1

solve system of non-linear implicit equations numerically

asked 2013-06-21 11:06:50 -0500

menturi628 gravatar image

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[0])^2 + (y-p[1])^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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-06-21 16:55:06 -0500

calc314 gravatar image

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[0]).subs(y==v0[1]).n()
    v0=v0-J.inverse()*F.subs(x==v0[0]).subs(y==v0[1])
    print v0, det(J)
F.subs(x==v0[0]).subs(y==v0[1])

This gives the solution to be:

(-0.333333333333334, -3.88888888888889)
edit flag offensive delete link more
0

answered 2017-02-14 07:29:54 -0500

this post is marked as community wiki

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

You can try minimizing d using sage.minimize.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-06-21 11:06:50 -0500

Seen: 1,188 times

Last updated: Feb 14