title: Normalize a vector so all sum of elements add to 1 everytime
body: <p>I am trying to write some code to normalize a vector with elements <code>[x,y,z]</code> but was wondering if there is a way to normalize the elements so that each time the sum of elements will add to 1.</p>
  
  <p>I did come across a formula: (pseudo code)</p>
  
  <pre><code>normalized = vectorA/ magnitude(vectorA)
  </code></pre>
  
  <p>However, if the <code>vectorA = [1,4,5]</code> then using the formula above would give:</p>
  
  <pre><code>magnitude = sqrt(1^2 + 4^2 + 5^2)
  magnitude = sqrt(42)
  magnitude = 6.48
  </code></pre>
  
  <p>Now based on that if I divide each element of the vector by <code>6.48</code> then:</p>
  
  <pre><code>1/6.48 = 0.154
  4/6.48 = 0.62
  5/6.48 = 0.77
  </code></pre>
  
  <p>As you can see, the sum is more than 1, so the formula doesn't work everytime and I was wondering if anyone has an idea on how to get the sum of elements to equal to 1 at all times.</p>
  
  <p>Any help will be appreciated</p>