# solving simultaneous equations

Here's my code:

x1, y1, x2, y2 = var('x1 y1 x2 y2')
eq1 = (x1-1)*(x1-2) + (y1-3)*(y1-4) == 0
eq2 = (x2-1)*(x2-2) + (y2-3)*(y2-4) == 0
eq3 = x1+x2 == 3
eq4 = y1+y2 == 7
sols = solve([eq1,eq2,eq3,eq4],x1,y1,x2,y2,solution_dict=True)
for soln in sols:
for varbl in soln:
print "{0} : {1},".format(varbl, soln[varbl])


And here's my output:

x1 + x2 : 3,
(x1 - 1)*(x1 - 2) + (y1 - 3)*(y1 - 4) : 0,
(x2 - 1)*(x2 - 2) + (y2 - 3)*(y2 - 4) : 0,
y1 + y2 : 7,


I'm looking for any solutions, exact or numerical approximation. Appreciate any help. I can solve the problem by hand, but obviously that's not the point here. I'm trying to find out what I'm doing wrong and learn to use sagemath cloud properly.

edit retag close merge delete

Does the system have a solution? Adapting code from this answer did not seem to work.

( 2015-11-07 21:19:32 +0200 )edit

I modified the title and retagged the post (and reformatted it) since it has nothing to do with the cloud, and the answer may be very helpful to many users.

( 2015-11-09 11:20:43 +0200 )edit

Note: this question is a followup of this ask question.

( 2015-11-09 11:23:37 +0200 )edit

Sort by » oldest newest most voted

As all these equations are polynomials, you should rather use polynomial methods:

sage: x1, y1, x2, y2=polygens(QQ,'x1,y1,x2,y2')
sage: eq1 = (x1-1)*(x1-2) + (y1-3)*(y1-4)
sage: eq2 = (x2-1)*(x2-2) + (y2-3)*(y2-4)
sage: eq3 = x1+x2 - 3
sage: eq4 = y1+y2 - 7
sage: I = x1.parent().ideal([eq1,eq2,eq3,eq4])
sage: I.variety()


This answers that the zero set has dimension 1, so you cannot hope for a finite set of solutions. Next

sage: I.elimination_ideal([x2,y2])
Ideal (x1^2 + y1^2 - 3*x1 - 7*y1 + 14) of Multivariate Polynomial Ring in x1, y1, x2, y2 over Rational Field


gives you the equation of the circle in the x1,y1 plane that describes the solutions.

more

Thanks! I see now.

( 2015-11-08 01:56:35 +0200 )edit