Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

assuming I have two vectors $A$ and $B$, where $A$ is completely known and from $B$ I know only that the first k components are 0. What is the maximum possible cosine value for the angle between the vectors given these constraints? (best case scenario for the remaining components of B)

All vector components are positive, so that the cosine will be between 0 and 1.

I found the formula $\frac{\sqrt{\sum_{i=k}^{n}{A_i^2}}}{\|A\|}$ myself using logic and experimenting, but I'm looking for a formal proof.

Geometrically it seems logically that the cosine should be highest when all the remaining components of $b$ equal the ones in $a$, but I don't have a proof for this either.

Cosine Similarity formula I'm using: $\cos(\theta) = {A \cdot B \over \|A\| \|B\|} = \frac{ \sum_{i=1}^{n}{A_i \times B_i} }{ \sqrt{\sum_{i=1}^{n}{(A_i)^2}} \times \sqrt{\sum_{i=1}^{n}{(B_i)^2}} }$

share|cite|improve this question
up vote 2 down vote accepted

You can write $A$ as $(A_\perp,A_\parallel)$ and $B$ as $(0,B_\parallel)$; then $A\cdot B=A_\parallel\cdot B_\parallel$ and $|B|=|B_\parallel|$, so $\cos\angle(A,B)=(|A_\parallel|/|A|)\cos\angle(A_\parallel,B_\parallel)$. The factor depends only on $A$, so the same $B$ maximizes the two cosines. Clearly $B_\parallel\parallel A_\parallel$ maximizes $\cos\angle(A_\parallel,B_\parallel)$ with maximal value $1$, and the corresponding maximal value of $\cos\angle(A,B)$ is the factor $|A_\parallel|/|A|$.

share|cite|improve this answer
thanks a lot! it took me a while to follow, but now it seems straight forward. – aKzenT Jan 30 '12 at 18:28
You're welcome. – joriki Jan 30 '12 at 22:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.