Ask Your Question
1

Not understanding behavior with solution to simultaneous quadratic equations

asked 2019-10-22 07:52:47 -0600

Justin Brody gravatar image

Hello,

I should preface this by saying I'm brand-new to sage so am probably missing some basics.

I'm writing because I wanted to use Sage to explore the behavior of a system of quadratic equations.

Here's my code

c = 299792458
eps1 = ( vector([9, 10, 10]).norm() -1 ) / c
eps2 = ( vector([9, -10, 10]).norm() -1 ) / c
eps3 = ( vector([-11, 10, 10]).norm() -1 ) / c
eps4 = ( vector([-11, -10, 10]).norm() -1 ) / c


x,y,z,D = var('x y z D')   # GPS solution
x1,y1,z1 = var('x1 y1 z1') # Coordinates of P1

eq1 =  (x - 10)^2 + (y - 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps1 - D)^2
eq2 =  (x - 10)^2 + (y + 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps2 - D)^2
eq3 =  (x + 10)^2 + (y - 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps3 - D)^2
eq4 =  (x + 10)^2 + (y + 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps4 - D)^2

If I solve the system with S = solve([eq1, eq2, eq3, eq4,D==0], x, y, z, D)I get symbolic solutions as expected (y is constantly 0 which is unexpected and doesn't seem right, but that's a different matter).

However, if I try to specify values for x1,y1,z1 by using solve([eq1, eq2, eq3, eq4, x1==0, y1==0, z1==0, D==0], x, y, z) it returns an empty list, which I assume means no solution. On the other hand, if I use my solution S from before and explicitly substitute x1==0, y1==0, z1==0, D==0 I get the solutions I'm expecting.

Could anyone explain this behavior? Is it somehow easier for Sage to solve the more general equation than the one with parameters plugged in? Will Sage sometimes fail to find existent solutions to such systems, or have I just done something wrong?

Many thanks, Justin

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-10-22 15:29:04 -0600

Emmanuel Charpentier gravatar image

Operating as you did, I get the same results. Furthermore, I get:

sage: solve([eq1, eq2, eq3, eq4, D==0, x1==0], [x, y, z, D])
[]

This, IMHO, means that sage concludes that no valye of x, y, z, d allows you to conclude that x1==0, which is indeed true. What is more annoying is that

sage: solve([eq1, eq2, eq3, eq4, D==0, x1==0], [x, y, z, D, x1])

never returns (you have to interrupt Sage in order to get tyour prompt back). This may be a bug...

But to get your solutions while instantiating tour parameters, you can write:

sage: [[eq.subs([x1==0, y1==0, z1==0]) for eq in s] for s in S]
[[x == 1, y == 0, z == 20, D == 0], [x == 1, y == 0, z == 0, D == 0]]

which looks entirely reasonable...

IMNSHO, the cleaner way to solve your problem is:

sage: S0=solve([eq1, eq2, eq3, eq4],[x,y,z])
sage: [[eq.subs([x1==0, y1==0, z1==0, D==0]) for eq in s] for s in S0]

totally separating variables (x, y, z) and parameters (D is a parameter...).

HTH,

edit flag offensive delete link more

Comments

What is more annoying is that

>    sage: solve([eq1, eq2, eq3, eq4, D==0, x1==0], [x, y, z, D, x1])

never returns (you have to interrupt Sage in order to get tyour prompt back). This may be a bug...

No it isn't : in this second case, x1 appears as an unknown and as a parameter. Sage is sort-of-forced to enter an infinite loop...

This could be detected, but probably requres a solver cleverer than Maxima's...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2019-10-22 15:41:20 -0600 )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

Stats

Asked: 2019-10-22 07:52:47 -0600

Seen: 24 times

Last updated: Oct 22