2
$\begingroup$

For example, I have to solve the following equations:

$$\left\{\begin{align*} &x^2 + y^2 + z^2 = 1\\ &Ax + By + Cz = 0 \end{align*}\right.$$

for $y$ and $z$, where $x$, $A$, $B$ and $C$ are known values. I need this for production. I guess I could solve this by hand, but there are many other of those and, if did all manually, my production would stop. Is there a software that solves this kind of situation?

  • 0
    Use a computer algebra system such as Mathematica, Maple, Macsyma etc... You could also look here http://www.sagemath.org/2012-12-18
  • 1
    That is the equation for the intersection of a sphere with a plane through the origin. The solution is a circle which is coplanar with the plane, and so there are an infinite number of solutions. Are there any other constraints that would narrow the list of answers?2012-12-18
  • 0
    @MarioCarneiro No, that's what I want to find: points on the circle of interception between the unit sphere and a plane. I just wanted a formula that I could feed with a vector and an angle, and it would return one of those points. Not having lucky trying to figure it out, though. Wolfram Alpha won't understand my inputs. If you know the answer I'll be very thankful if you told me, but even better I'd be served with a program that did that kind of stuff.2012-12-18
  • 0
    @Learner I've considered those, but they are too big and I have no idea where to look for what I'm needing here. Do you?2012-12-18
  • 1
    @Dokkat What do you mean by too big? In any case, you could use Sage from the web at this URL http://www.sagenb.org/2012-12-18
  • 0
    Try http://www.wolframalpha.com/input/?i=solve+x%5E2%2By%5E2%2Bz%5E2-1%3D0%2C+z-2y%2B3x%3D0 . Note the usage of specific $A$,$B$,$C$; it doesn't seem to like the general equation.2012-12-18
  • 0
    Typing `Solve[{x^2 + y^2 + z^2 - 1 == 0, A x + B y + C z == 0}, {y, z}]` into Mathematica gets me the (ugly) answer.2012-12-18
  • 0
    @MarioCarneiro would you kindly post the answer as I don't have the software? Is there a free Mathematica?2012-12-18
  • 1
    Wolfram Alpha *is* free Mathematica. Mathematica proper isn't cheap; you can get a copy for under $200 if you are a student, but there are also methods that I *wholeheartedly do not recommend* to get a copy for free.2012-12-18
  • 0
    @MarioCarneiro I see, but is it such a mythical piece of software without replacement on the market? (For some reason couldn't notify you from the comment on the answer.)2012-12-18
  • 0
    Not really. I'm quite partial to Mathematica, and I'm probably three steps removed from working at Wolfram, but Matlab and some more nameless CAS systems do exist out there. Just google https://www.google.com/search?q=computer+algebra+system .2012-12-18

3 Answers 3

1

Based on Mario Carneiro's comment, you can do just this:

Let $V = (A,B,C)$ be a vector. Your equation is asking for the set of points $(x,y,z)$ on the unit sphere that is orthogonal to $V$.

  1. If $A = B = 0$ we have that the circle is just the circle in the $x, y$ plane. So you can parametrise as normal: $\theta \mapsto (\cos\theta, \sin\theta, 0)$ would give you points on this circle by angle.

  2. If at least one of $A,B$ are not zero you can rotate the unit circle from the $x,y$ plane via an orthogonal transformation. We do this by constructing an orthogonal matrix that sends the $z$ axis to the subspace spanned by the vector $V$. Since orthogonal transformations preserve length and angles, the image of the unit circle from the $x,y$ plane under this orthogonal transformation would be the circle you want. There are lots of ways to do this. We choose one here that is algebraically simpler.

    Set the vectors $W_3 = V$, $W_2 = (B, -A, 0)$, $W_1 = (-AC,-BC,B^2+A^2)$. A direct computation will verify to you that the three are orthogonal. Set $U_3 = W_3 / \|W_3\|$ where $\|\cdot\|$ is the vector 2-norm, so $U_3 = W_3 / \sqrt{A^2 + B^2 + C^2}$. Set $U_2 = W_2 / \|W_2\|$ and set $U_1 = W_1 / \|W_1\|$. Now the matrix $O$ whose columns are given by the vectors $U_1, U_2, U_3$ is orthogonal. And it maps the $z$ axis to the subspace spanned by $U_3$, which is also the subspace spanned by $V$.

    So the following mapping would give you a parametrisation of the required circle: $$ \theta \mapsto \cos\theta U_1 + \sin\theta U_2 $$ for completeness we expand the definition of $U_1$ and $U_2$ to get $$ \theta \mapsto \cos\theta \frac{(-AC, -BC, A^2 + B^2)}{\sqrt{ (A^2 + B^2+ C^2)(A^2 + B^2)}} + \sin\theta \frac{(B,-A,0)}{\sqrt{A^2 + B^2}} $$ Note that when at least one of $A,B$ is non-zero, the denominators are non-zero and so the mapping is well defined.

One caveat: because of the method of construction, the family of maps is discontinuous in $(A,B,C)$ as $A,B$ both approach 0. This is why we have to fill in the edge case specifically in step 1.


In view of Dokkat's comment below, let me quickly describe the construction of $O$ and the choice of $W_1,W_2,W_3$. The first thing to remember from linear algebra is that

If $O$ is the matrix corresponding to an orthogonal transformation, then its column vectors form an orthonormal basis of the vector space, and vice versa.

Furthermore, if the column vectors of $O$ are $U_1, U_2, U_3$ in order, then the vector $(0,0,1)$ would be mapped to $U_3$ by the transformation $O$ by matrix multiplication.

So to get our desired $O$ (which sends the $z$ axis to the subspace spanned by $V$), we need that $U_3$ is the unit vector corresponding to $V$. Then we just need to find $U_1, U_2$ such that $U_1, U_2, U_3$ together is an orthonormal basis.

Given that the direction of $U_3$ is fixed, we first fix the directions of $U_1$ and $U_2$. After we fix the directions, we can just take the unit vectors in those directions to fix the length.

To fix the directions we observe the following two facts:

  • Suppose $A \neq 0$, the vector $(A,B,C)$ is perpendicular to the vector $(B,-A,0)$. This is an analogue of "rotating by 90 degrees in the plane" when we think about vectors in a plane. Note that we keep only the $x,y$ components and drop the $z$ component. You can do this in also higher dimensional spaces. We set $W_2$ to be this vector.

  • In 3D space, we have the cross product. Which has the nice property that given vectors $\vec{v}, \vec{w}$, their cross product $\vec{v}\times \vec{w}$ is perpendicular to either $\vec{v}$ or $\vec{w}$. Using this property we set $W_1 = W_2 \times W_3$. (Or maybe the negative of that, I forgot which sign I took.)

Then the $W_1, W_2, W_3$ will be mutually orthogonal nonvanishing vectors.

  • 0
    This is a good solution; I forgot to mention that liberal usage of variable substitution can often simplify an ugly result. I'd just like to mention that although both my solution and Willie's are correct, the answers are quite different, because he is finding a parametrization $(x(\theta),y(\theta),z(\theta))$ for the circle, and I am solving explicitly for $(x,y(x),z(x))$. In principle, you could invert the $x(\theta)$ equation and substitute into $y$ and $z$ to get my answer, but I know that will involve lots of messy algebra, so I don't recommend it.2012-12-18
  • 0
    @WillieWong great answer, the parametrisation makes it easier to find properly spaced vectors. I can get most of what you did, except for the choice of W3=V, W2=(B,−A,0), W1=(−AC,−BC,B2+A2), which regardless of what you say I know it came from dark magic. Thank you very much!2012-12-18
2

You may consult Maple to do this for you by the following codes. However, knowing the unknown coefficients make the way of finding the variables easier.

[> solve({x^2+y^2+z^2 = 1, A*x+B*y+C*z = 0}, {y, z});   {y = -(A*x+C*RootOf((C^2+B^2)*_Z^2+2*A*x*C*_Z+x^2*B^2+A^2*x^2-B^2))/B, z = RootOf((C^2+B^2)*_Z^2+2*A*x*C*_Z+x^2*B^2+A^2*x^2-B^2)} 
1

Hot off the Mathematica presses:

> Solve[{x^2 + y^2 + z^2 - 1 == 0, A x + B y + C z == 0}, {y, z}] // Simplify 

$$\begin{align} \Bigg\{\Bigg\{y & \to -\frac{A B x+\sqrt{-C^2 \left(A^2 x^2+B^2 \left(-1+x^2\right)+C^2 \left(-1+x^2\right)\right)}}{B^2+C^2}, \\ z & \to \frac{-A C^2 x+B \sqrt{-C^2 \left(A^2 x^2+B^2 \left(-1+x^2\right)+C^2 \left(-1+x^2\right)\right)}}{C \left(B^2+C^2\right)}\Bigg\}, \\ \Bigg\{y & \to \frac{-A B x+\sqrt{-C^2 \left(A^2 x^2+B^2 \left(-1+x^2\right)+C^2 \left(-1+x^2\right)\right)}}{B^2+C^2}, \\ z & \to -\frac{A C^2 x+B \sqrt{-C^2 \left(A^2 x^2+B^2 \left(-1+x^2\right)+C^2 \left(-1+x^2\right)\right)}}{C \left(B^2+C^2\right)}\Bigg\}\Bigg\} \\ \end{align}$$

I have intentionally not simplified these equations, so as to give you a feel what Mathematica solutions are like.

  • 0
    Thanks. This is great and will probably solve my problem, even if in a magical way, because, except for creating an initial scenario, I have no idea of what happened there. I've just figured out how to get a similar answer from Sage and will probably be using this same method more times; with a little discomfort, though, because it seems I'm missing some learning and doing things the hacky way. Just for curiosity, how would mathematicians actually deal with this problem?2012-12-18
  • 1
    Well, you could solve it yourself, but Mathematica is my go-to for tedious or highly computational problems (or for checking my algebra and making quick plots).2012-12-18
  • 0
    so are you often doing the same thing you did here? Getting ugly solutions and all? No problems on it?2012-12-18
  • 0
    Usually the problem itself is nicer. In this case, there are no useful symmetries or anything to take advantage of, to the solution in full generality has no choice but to be this hideous.2012-12-18