Ask Your Question
1

solving simultaneous equations

asked 9 years ago

ameetnsharma gravatar image

updated 9 years ago

tmonteil gravatar image

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.

Preview: (hide)

Comments

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

fidbc gravatar imagefidbc ( 9 years ago )

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.

tmonteil gravatar imagetmonteil ( 9 years ago )

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

tmonteil gravatar imagetmonteil ( 9 years ago )

1 Answer

Sort by » oldest newest most voted
3

answered 9 years ago

FrédéricC gravatar image

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.

Preview: (hide)
link

Comments

Thanks! I see now.

ameetnsharma gravatar imageameetnsharma ( 9 years ago )

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 9 years ago

Seen: 1,481 times

Last updated: Nov 09 '15