ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 22 Oct 2019 15:41:20 -0500Not understanding behavior with solution to simultaneous quadratic equationshttps://ask.sagemath.org/question/48466/not-understanding-behavior-with-solution-to-simultaneous-quadratic-equations/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 Tue, 22 Oct 2019 07:52:47 -0500https://ask.sagemath.org/question/48466/not-understanding-behavior-with-solution-to-simultaneous-quadratic-equations/Answer by Emmanuel Charpentier for <p>Hello,</p>
<p>I should preface this by saying I'm brand-new to sage so am probably missing some basics. </p>
<p>I'm writing because I wanted to use Sage to explore the behavior of a system of quadratic equations. </p>
<p>Here's my code</p>
<pre><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
</code></pre>
<p>If I solve the system with <code>S = solve([eq1, eq2, eq3, eq4,D==0], x, y, z, D)</code>I get symbolic solutions as expected (y is constantly 0 which is unexpected and doesn't seem right, but that's a different matter). </p>
<p>However, if I try to specify values for x1,y1,z1 by using <code>solve([eq1, eq2, eq3, eq4, x1==0, y1==0, z1==0, D==0], x, y, z)</code> it returns an empty list, which I assume means no solution. On the other hand, if I use my solution <code>S</code> from before and explicitly substitute <code>x1==0, y1==0, z1==0, D==0</code> I get the solutions I'm expecting.</p>
<p>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?</p>
<p>Many thanks,
Justin </p>
https://ask.sagemath.org/question/48466/not-understanding-behavior-with-solution-to-simultaneous-quadratic-equations/?answer=48475#post-id-48475Operating 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,
Tue, 22 Oct 2019 15:29:04 -0500https://ask.sagemath.org/question/48466/not-understanding-behavior-with-solution-to-simultaneous-quadratic-equations/?answer=48475#post-id-48475Comment by Emmanuel Charpentier for <p>Operating as you did, I get the same results. Furthermore, I get:</p>
<pre><code>sage: solve([eq1, eq2, eq3, eq4, D==0, x1==0], [x, y, z, D])
[]
</code></pre>
<p>This, IMHO, means that sage concludes that no valye of <code>x, y, z, d</code> allows you to conclude that <code>x1==0</code>, which is indeed true. What is more annoying is that</p>
<pre><code>sage: solve([eq1, eq2, eq3, eq4, D==0, x1==0], [x, y, z, D, x1])
</code></pre>
<p>never returns (you have to interrupt Sage in order to get tyour prompt back). This may be a bug...</p>
<p>But to get your solutions while instantiating tour parameters, you can write:</p>
<pre><code>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]]
</code></pre>
<p>which looks entirely reasonable...</p>
<p>IMNSHO, the cleaner way to solve your problem is:</p>
<pre><code>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]
</code></pre>
<p>totally separating variables (x, y, z) and parameters (D <em>is</em> a parameter...).</p>
<p>HTH,</p>
https://ask.sagemath.org/question/48466/not-understanding-behavior-with-solution-to-simultaneous-quadratic-equations/?comment=48477#post-id-48477> 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...Tue, 22 Oct 2019 15:41:20 -0500https://ask.sagemath.org/question/48466/not-understanding-behavior-with-solution-to-simultaneous-quadratic-equations/?comment=48477#post-id-48477