ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 14 Feb 2017 14:29:54 +0100solve system of non-linear implicit equations numericallyhttps://ask.sagemath.org/question/10269/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[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,
menturiFri, 21 Jun 2013 18:06:50 +0200https://ask.sagemath.org/question/10269/solve-system-of-non-linear-implicit-equations-numerically/Answer by calc314 for <p>I am attempting to solve for a solution of a system of two non-linear implicit equations using the following code:</p>
<pre><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)
</code></pre>
<p>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.</p>
<p>Does there exist a numeric solver which is capable of solving a system of this form? What other alternatives are there?</p>
<p>Thanks,
menturi</p>
https://ask.sagemath.org/question/10269/solve-system-of-non-linear-implicit-equations-numerically/?answer=15117#post-id-15117I'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)Fri, 21 Jun 2013 23:55:06 +0200https://ask.sagemath.org/question/10269/solve-system-of-non-linear-implicit-equations-numerically/?answer=15117#post-id-15117Answer by maaaaaaartin for <p>I am attempting to solve for a solution of a system of two non-linear implicit equations using the following code:</p>
<pre><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)
</code></pre>
<p>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.</p>
<p>Does there exist a numeric solver which is capable of solving a system of this form? What other alternatives are there?</p>
<p>Thanks,
menturi</p>
https://ask.sagemath.org/question/10269/solve-system-of-non-linear-implicit-equations-numerically/?answer=36615#post-id-36615You can try minimizing `d` using `sage.minimize`.Tue, 14 Feb 2017 14:29:54 +0100https://ask.sagemath.org/question/10269/solve-system-of-non-linear-implicit-equations-numerically/?answer=36615#post-id-36615