## Linear Algebra - Find an N-Dimensional Vector Orthogonal to A Given Vector

### Remember to vote up questions/answers you find interesting or helpful (requires 15 reputation points)

I'm writing an eigensolver and I'm trying to generate a guess for the next iteration in the solve that is orthogonal to to all known eigenvectors calculated thus far. This means that if I have only one eigenvector, that is say 2 million entries long, I need to generate a vector orthogonal to it. I don't think Gram Schmidt works here because I don't have a set of vectors to orthogonalize. What I have is a single vector, in the first eigensolve, and I need to generate another that is orthogonal.

So, in summary: given one vector, create from nothing another vector which is orthogonal to it. The method must support N-Dimensional vectors (where N could be millions).

I should add that writing a generalized cross product algorithm is not appealing. I'd prefer another way.

-

1
Are there any other constraints? Otherwise, let $a$ be the given vector. If $a_1=0$, then $(1,0,0,\dots)$ works; if $a_2=0$, then $(0,1,0,0,\dots)$ works; otherwise, $(a_2,-a_1,0,0,\dots)$ works. – Klaus Draeger Feb 6 2012 at 17:21
Guess (perhaps by coin flipping) the first say 7/8 of the coordinates, and then use guessing or algebra to determine the rest. This method will rarely fail, and usually because some small set of coordinates are supposed to be zero instead of nonzero. Gerhard "Ask Me About System Design" Paseman, 2012.02.06 – Gerhard Paseman Feb 6 2012 at 17:21
Very useful comments, thank you. – wavepacket Feb 6 2012 at 17:41

## 2 Answers

Suppose the vector is $(x_1,x_2,\dots)$. The following algorithm should work:

1. If $x_1=0$ then take $(1,0,0,\dots)$.

2. If $x_1$ is non-zero and $x_2=0$ then take $(0,1,0,0,\dots)$.

3. If $x_1$ and $x_2$ are non-zero then take $(-x_2,x_1,0,0,\dots)$

-

This seems to be a popular answer. I'll give it a shot, thanks. – wavepacket Feb 6 2012 at 17:41
Just for the record - 2 and 3 are in fact applications of the same rule :-) – Vladimir Dotsenko Feb 6 2012 at 18:56

### You can accept an answer to one of your own questions by clicking the check mark next to it. This awards 15 reputation points to the person who answered and 2 reputation points to you.

Actually you might use Gram Schmidt here.

Given a set of ortogonal vectors $x_1,x_2,\ldots,x_k$ you can use Gram-Shmidt algorithm for set of vectors ${x_1,x_2,...,x_k,e_i}$ adding basis vector to system of ortogonalysed vectors (note that you need use Gram Schmidt procedure only to find last vector since first k vectors are already orthogonal). Then (since vectors $e_1,e_2,\ldots,e_{k+1}$ are linearly independent) for some i between 1 and k+1 Gram Schmidt will give you non-zero vector which is ortogonal to given vectors $x_1,x_2,\ldots,x_k$

So to find a guess you simply need to use Gram Schmidt procedure several times (no more than k+1 for the first guess and no more then two times for next guesses).

To simplify this procedure you can do this only with first $k+1$ coordinates of vectors, so you will find a vector of form $(y_1,y_2,\ldots,y_{k+1},0,0,\ldots)$. Answers of Kapil and Klaus are actually equivalent to using this route.

-

Or just choose the next vector randomly. In particular, what's wrong with doing Gram-Schmidt to a set of randomly generated vectors? – Deane Yang Feb 6 2012 at 20:10
nothing wrong I guess, don't know if probabilistys algorithm qualifies as an answer to op, so I chose deterministic one. – Ostap Chervak Feb 7 2012 at 20:35
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 21, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9225122928619385, "perplexity_flag": "middle"}