# How can I convert a general ellipsoid equation into a vector form in MATLAB?

What function can I use in MATLAB or how by hand can I convert the ellipsoid: $$\frac{(x+12t-11)^2}{4}+y^2+z^2-1=0$$

into matrix form, from the form $$X^\top {\rm A} X = 0$$

$$X=\pmatrix{x \\ y \\ z \\ 1}$$

For correction and testing see the following

There's almost certainly no function for this. But you can just let $u = -12t + 11$ and then create the matrix $$A = \begin{bmatrix} \frac{1}{4} & 0 & 0 & \frac{u}{4}\\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ \frac{u}{4} & 0 & 0 & -1 + \frac{u^2}{4} \end{bmatrix}$$

You could just put $u/2$ in one corner or the other, but I prefer the symmetric form, so it's what I've provided. I might be slightly off here, but if you just multiply out $X'AX$ and see whether it gives the right equation, you'll see that what I've written is either right or really close.

In (untested) code:

u = -12*t + 11;
A = eye(4);
A(1,1) = 1/4; A(4, 4) = -1 + u*u/4;
A(1, 4) = u/4; A(4, 1) = u/4;

• why there is no function for this? Jul 17, 2017 at 15:18
• Because it amounts to about 4 lines of code. If you need such a function, you just write it! Also: that's not a math question, it's a Matlab question, hence inappropriate for this site. Jul 17, 2017 at 15:24

I got $$\pmatrix{x \\ y \\ z \\ 1}^\top \begin{bmatrix} \frac{1}{4} &0 & 0 & \frac{12 t-11}{4} \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ \frac{12 t-11}{4} & 0 & 0 & \frac{3 (48 t^2-88 t+39)}{4} \end{bmatrix} \pmatrix{x \\ y \\ z \\1} =0$$

How?

I matched coefficients with $$\pmatrix{x \\ y \\ z \\ 1}^\top \begin{bmatrix} A_{11} & & & A_{14} \\ & A_{22} & & & \\ & & A_{33} & \\ A_{14} & & & A_{44} \end{bmatrix} \pmatrix{x \\ y \\ z \\ 1} =$$

$$\frac{(x+12t-11)^2}{4}+y^2+z^2-1 = A_{11} x^2 +2 A_{14} x + A_{22} y^2 + A_{33} z^2 + A_{44} = 0$$

The reason I picked those elements of the coefficient matrix ${\rm A}$ is because the expression only contains terms of $x^2$, $x$, $y^2$, $z^2$ and a constant term.

## In General

$$\begin{bmatrix} A_{11} & 0 & 0 & A_{14} \\ 0 & A_{22} & 0 & A_{24} \\ 0 & 0 & A_{33} & A_{34} \\ A_{14} & A_{24} & A_{34} & A_{44} \end{bmatrix} \Longrightarrow A_{11} x^2 + A_{22} y^2 + A_{33} z^2 + 2 A_{14} x + 2 A_{24} y + 2 A_{34} z + A_{44} = 0$$

$$\frac{(x-x_c)^2}{a^2} + \frac{(y-y_c)^2}{b^2} + \frac{(z-z_c)^2}{c^2} = 1 \Longrightarrow \begin{bmatrix} \frac{1}{a^2} & 0 & 0 & -\frac{x_c}{a^2} \\ 0 & \frac{1}{b^2} & 0 & -\frac{y_c}{b^2} \\ 0 & 0 & \frac{1}{c^2} & -\frac{z_c}{c^2} \\ -\frac{x_c}{a^2} & -\frac{y_c}{b^2} & -\frac{z_c}{c^2} & \kappa^2-1 \end{bmatrix}$$

where $\kappa^2 = \frac{x_c^2}{a^2}+\frac{y_c^2}{b^2}+\frac{z_c^2}{c^2}$

• I added some general expressions that might help you from equation to matrix coefficient form and back. Jul 18, 2017 at 13:36