# Solve a simple system of non-linear equations

 2 Maple can solve a system of equations such as $\sin x + y =0, \sin x - y =0$. However, var('x y') solve([sin(x) + y ==0, sin(x) - y==0], [x, y]) produces no useful answer. Is there any other way to proceed? asked Dec 15 '11 jllb 21 ● 1 ● 1 ● 5

 2 First, even though this particular system can be solved by hand easily enough, giving a nice, tidy family of solutions, I don't suspect that Sage will be able to see that. (Somebody please correct me if I'm wrong on that.) Certainly this is the case if you change your equations a little bit. In general, the best you can hope for is numerical solutions. Resigning ourselves to that, I found a couple other questions on ASKSAGE with similar issues: here and here. My answer below is heavily cribbed from the one given by DSM at the first link. He recommends using scipy's 'minimize' function. from scipy import optimize  Then, given a starting point, e.g. (5,4), we hunt for a nearby solution. sage: f(x,y) = (sin(x) + y, sin(x) - y) sage: minimize(norm(f), (5,4), disp = 0) (6.28318530718, 8.79023942731e-19)  If you loop over a lattice of points, you will hopefully find all the solutions in that region: sage: short = lambda (x,y): (x.n(20), y.n(20)) # To cut down on the number of digits displayed. sage: for startloc in CartesianProduct([-6,-2 .. 6],[-6,-2 .. 6]): ....: sol = minimize(norm(f), startloc, disp = 0) ....: print startloc," ", short(sol), " ",short(f(*sol)) [-6, -6] (-6.2832, 4.8257e-19) (2.4541e-16, 2.4445e-16) [-6, -2] (-6.2832, 2.0430e-19) (-6.4304e-16, -6.4345e-16) [-6, 2] (-6.2832, -2.0430e-19) (-6.4345e-16, -6.4304e-16) [-6, 6] (-6.2832, -4.8257e-19) (2.4445e-16, 2.4541e-16) [-2, -6] (-3.1416, -4.7943e-19) (-1.2294e-16, -1.2199e-16) [-2, -2] (-3.1416, 1.0451e-19) (-1.2236e-16, -1.2257e-16) [-2, 2] (-3.1416, -1.0451e-19) (-1.2257e-16, -1.2236e-16) [-2, 6] (-3.1416, 4.7943e-19) (-1.2199e-16, -1.2294e-16) [2, -6] (3.1416, -4.7943e-19) (1.2199e-16, 1.2294e-16) [2, -2] (3.1416, 1.0451e-19) (1.2257e-16, 1.2236e-16) [2, 2] (3.1416, -1.0451e-19) (1.2236e-16, 1.2257e-16) [2, 6] (3.1416, 4.7943e-19) (1.2294e-16, 1.2199e-16) [6, -6] (6.2832, 4.8257e-19) (-2.4445e-16, -2.4541e-16) [6, -2] (6.2832, 2.0430e-19) (6.4345e-16, 6.4304e-16) [6, 2] (6.2832, -2.0430e-19) (6.4304e-16, 6.4345e-16) [6, 6] (6.2832, -4.8257e-19) (-2.4541e-16, -2.4445e-16)  posted Dec 16 '11 jdc 215 ● 1 ● 4 ● 15 http://jconecker.wordpres...

[hide preview]