Ask Your Question
1

solving simultaneous equations

asked 2015-11-07 19:21:00 +0100

ameetnsharma gravatar image

updated 2015-11-09 11:22:04 +0100

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.

edit retag flag offensive close merge delete

Comments

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

fidbc gravatar imagefidbc ( 2015-11-07 21:19:32 +0100 )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.

tmonteil gravatar imagetmonteil ( 2015-11-09 11:20:43 +0100 )edit

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

tmonteil gravatar imagetmonteil ( 2015-11-09 11:23:37 +0100 )edit

1 Answer

Sort by » oldest newest most voted
3

answered 2015-11-07 22:17:37 +0100

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.

edit flag offensive delete link more

Comments

Thanks! I see now.

ameetnsharma gravatar imageameetnsharma ( 2015-11-08 01:56:35 +0100 )edit

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: 2015-11-07 19:21:00 +0100

Seen: 1,445 times

Last updated: Nov 09 '15