Skip to main content
Mathematics LibreTexts

9.2: Calculating Vector Length, Normalization, Distance and Dot

  • Page ID
    64302
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    #  Load Useful Python Libraries
    import numpy as np
    import sympy as sym
    sym.init_printing(use_unicode=True)
    from urllib.request import urlretrieve
    urlretrieve('https://raw.githubusercontent.com/colbrydi/jupytercheck/master/answercheck.py', 
                'answercheck.py');

    In this section we will cover some of the basic vector math we will use this semester.

    Do This

    Watch the following summary video about calculation of vector length, Normalizing vectors and the distance between points then answer the questions.

    from IPython.display import YouTubeVideo
    YouTubeVideo("S0BIhbV6reI",width=640,height=360, cc_load_policy=True)

    Vector:

    \[(a_1, a_2, \dots a_n) \nonumber \]

    \[(b_1, b_2, \dots b_n) \nonumber \]

    Length:

    \[length = \sqrt{a_1^2 + a_2^2 + \dots + a_n^2} \nonumber \]

    Normalization:

    \[\frac{1}{length}(a_1, a_2, \dots a_n) \nonumber \]

    Distance:

    \[distance = \sqrt{(a_1 - b_1)^2 + (a_2 - b_2)^2 + \dots + (a_n - b_n)^2} \nonumber \]

    Question

    Calculate length of vector (4.5, 2.6, 3.3, 4.1)?

    #Put your answer to the above question here
    from answercheck import checkanswer
    
    checkanswer.float(length,'695da96d4a240e54bd8c61e75ff5a3e2');
    Question

    What is a normalized form of the vector (4.5, 2.6, 3.3, 4.1)?

    #Put your answer to the above question here
    from answercheck import checkanswer
    
    checkanswer.vector(norm,'12c94f16ba11222987ca20006790182d');
    Question

    What is the distance between (4.5, 2.6, 3.3, 4.1) and (4, 3, 2, 1)?

    #Put your answer to the above question here
    from answercheck import checkanswer
    
    checkanswer.float(distance,'d73defc9a514eb70434190e1757f5bb8');

    Dot Product:

    \[dot(a,b) = a_1b_1 + a_2b_2 +\dots + a_nb_n \nonumber \]

    Do This

    Review Sections 1.4 and 1.5 of the Boyd and Vandenberghe text and answer the questions below.

    Question

    What is the dot product between \(u=[1,7,9,11]\) and \(v=[7,1,2,2]\) (Store the information in a variable called uv)?

    #Put your answer to the above question here
    from answercheck import checkanswer
    
    checkanswer.float(uv,'48044bf058c2d7d21b311b173a0ca7e5');
    Question

    What is the norm of vector \(u\) defined above (store this value in a variabled called n)?

    #Put your answer to the above question here
    from answercheck import checkanswer
    
    checkanswer.float(n,'96078eb552924d7bdb9e67f9ecab88c1');
    Question

    What is the distance between points \(u\) and \(v\) defined above. (put your answer in a variable named d)

    #Put your answer to the above question here
    from answercheck import checkanswer
    
    checkanswer.float(d,'71f49beeb28061bc60eb3d9966497416');

    This page titled 9.2: Calculating Vector Length, Normalization, Distance and Dot is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?