chriscatalfo.comJekyll2018-02-20T22:09:13-05:00http://chriscatalfo.com/Chris Catalfohttp://chriscatalfo.com/ccatalfo@gmail.com<![CDATA[Linear Algebra: More operations on vectors]]>http://chriscatalfo.com/articles/linalg-32015-04-05T00:00:00-04:002015-04-05T00:00:00-04:00Chris Catalfohttp://chriscatalfo.comccatalfo@gmail.com<p>If you didn’t read the first post in this series, you might want to <a href="/articles/linalg-intro">read that first</a>.</p>
<p><a href="/articles/linalg-2">Last time</a> we talked about adding vectors:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">listA</span> <span class="o">+</span> <span class="n">listB</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="o">+</span><span class="mi">10</span><span class="p">,</span><span class="mi">2</span><span class="o">+</span><span class="mi">11</span><span class="p">,</span><span class="mi">3</span><span class="o">+</span><span class="mi">12</span><span class="p">,</span><span class="mi">4</span><span class="o">+</span><span class="mi">13</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">11</span><span class="p">,</span><span class="mi">13</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">17</span><span class="p">]</span></code></pre></figure>
<p>or, with fancy math typesetting:</p>
<script type="math/tex; mode=display">% <![CDATA[
\left[\begin{array}{cccc}
1 & 2 & 3 & 4
\end{array}\right]
+
\left[\begin{array}{cccc}
10 & 11 & 12 & 13
\end{array}\right]
=
\left[\begin{array}{cccc}
12 & 13 & 15 & 17
\end{array}\right] %]]></script>
<p>One thing we might like to do with vectors is change all of the elements by
some specified amount via multiplication. Multiply them all by 2, for example.</p>
<p>In pretend linear algebra style Python:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">listA</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">6</span><span class="p">,</span><span class="mi">8</span><span class="p">]</span>
<span class="c"># listA = [4,8,12,16]</span></code></pre></figure>
<script type="math/tex; mode=display">% <![CDATA[
2 *
\left[\begin{array}{cccc}
2 & 4 & 6 & 8
\end{array}\right]
=
\left[\begin{array}{cccc}
4 & 8 & 12 & 16
\end{array}\right] %]]></script>
<p>This multiplies every element in the list by a given number.</p>
<p><a href="http://chriscatalfo.com/articles/linalg-3">Linear Algebra: More operations on vectors</a> was originally published by Chris Catalfo at <a href="http://chriscatalfo.com">chriscatalfo.com</a> on April 05, 2015.</p><![CDATA[Linear Algebra: Operations on vectors]]>http://chriscatalfo.com/articles/linalg-22015-03-18T00:00:00-04:002015-03-18T00:00:00-04:00Chris Catalfohttp://chriscatalfo.comccatalfo@gmail.com<h3 id="last-time">Last time</h3>
<p>If you didn’t read the first post, you might want to <a href="/articles/linalg-intro">read that first</a>.</p>
<h3 id="so-we-have-vectors">So, we have vectors</h3>
<p>Lists of things. What can we do with lists of things?</p>
<p>If the elements of the lists are addable we could try adding them.</p>
<p>What would it mean to add 2 lists of numbers?</p>
<p>Suppose we have two lists, call them listA and listB:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">listA</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">]</span>
<span class="n">listB</span> <span class="o">=</span> <span class="p">[</span><span class="mi">10</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">12</span><span class="p">,</span><span class="mi">13</span><span class="p">]</span></code></pre></figure>
<p>What should, in the context of Linear Algebra, adding these two lists mean?</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">listA</span> <span class="o">+</span> <span class="n">listB</span></code></pre></figure>
<p>If these were regular Python lists, or likely lists in any programming language, we’d probably get
the <em>concatenation</em> of the two lists, like this:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">listA</span> <span class="o">+</span> <span class="n">listB</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">11</span><span class="p">,</span><span class="mi">12</span><span class="p">,</span><span class="mi">13</span><span class="p">]</span></code></pre></figure>
<p>In Linear Algebra, however, we were talking about <em>adding</em> the numbers. So what would that mean?</p>
<p>We <em>could</em> add some permutation of the numbers to eachother. Maybe the 1st element gets added to the 4th and then the 2nd and 3rd elements get added.</p>
<p>That would be like this:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">listA</span> <span class="o">+</span> <span class="n">listB</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="o">+</span><span class="mi">13</span><span class="p">,</span><span class="mi">2</span><span class="o">+</span><span class="mi">12</span><span class="p">,</span><span class="mi">3</span><span class="o">+</span><span class="mi">11</span><span class="p">,</span><span class="mi">4</span><span class="o">+</span><span class="mi">10</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">14</span><span class="p">,</span><span class="mi">14</span><span class="p">,</span><span class="mi">14</span><span class="p">,</span><span class="mi">14</span><span class="p">]</span></code></pre></figure>
<p>That seems … odd, though, doesn’t it? And hard to remember.</p>
<p>Also one would think that corresponding elements in the two vectors would have some
relationship to one another. Maybe they’re the distance from the x-axis. Or maybe
they’re both the height in centimeters of a certain book.</p>
<p>If corresponding elements have a relationship it seems like it would make sense to
add them.</p>
<p>Using that rule then, we’d have:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">listA</span> <span class="o">+</span> <span class="n">listB</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="o">+</span><span class="mi">10</span><span class="p">,</span><span class="mi">2</span><span class="o">+</span><span class="mi">11</span><span class="p">,</span><span class="mi">3</span><span class="o">+</span><span class="mi">12</span><span class="p">,</span><span class="mi">4</span><span class="o">+</span><span class="mi">13</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="mi">11</span><span class="p">,</span><span class="mi">13</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">17</span><span class="p">]</span></code></pre></figure>
<p>If we want to write that in a more mathematical style, we could write:</p>
<script type="math/tex; mode=display">% <![CDATA[
\left[\begin{array}{cccc}
1 & 2 & 3 & 4
\end{array}\right]
+
\left[\begin{array}{cccc}
10 & 11 & 12 & 13
\end{array}\right]
=
\left[\begin{array}{cccc}
12 & 13 & 15 & 17
\end{array}\right] %]]></script>
<p>Usually we like to give a general rule for an algorithm like this.</p>
<p>For two vectors with elements <script type="math/tex">a</script> and <script type="math/tex">b</script>, the <script type="math/tex">nth</script> element of the resulting vector <script type="math/tex">\mathbf{c}</script> is given by:</p>
<script type="math/tex; mode=display">c_n = a_n + b_n</script>
<p>That’s all for now. Next time: more operations we can perform on vectors.</p>
<p><a href="http://chriscatalfo.com/articles/linalg-2">Linear Algebra: Operations on vectors</a> was originally published by Chris Catalfo at <a href="http://chriscatalfo.com">chriscatalfo.com</a> on March 18, 2015.</p><![CDATA[Linear Algebra: a very very very short intro]]>http://chriscatalfo.com/articles/linalg-intro2015-03-15T00:00:00-04:002015-03-15T00:00:00-04:00Chris Catalfohttp://chriscatalfo.comccatalfo@gmail.com<h2 id="what-is-this-thing-called-linear-algebra">What is this thing called Linear Algebra?</h2>
<p>I’ve decided to learn linear algebra, so here I am.</p>
<p>What is linear algebra? That’s what we’re here to find out.</p>
<p>I’ll be using various sources to learn, including the Coding the Matrix coursera course, Gilbert Strang’s
online course, and other materials I find here and there.</p>
<h2 id="a-first-taste">A first taste</h2>
<p>Before we dive right in here’s a first taste of what it’s about, as far as I’ve learned so far.</p>
<p>Say we have a list of numbers we need to work with. Maybe a list of numbers indicating dimensions of
books, in cm.</p>
<script type="math/tex; mode=display">% <![CDATA[
\left[\begin{array}{cccc}
12 & 10 & 15 & 11
\end{array}\right] %]]></script>
<p>It is sometimes convenient to work with this list of numbers such as this as one unit, in which case we can call it a <em>vector</em> of numbers.</p>
<h3 id="dimension-of-a-vector">Dimension of a vector</h3>
<p>The preceding vector has 4 “things in it”, or <em>elements</em>, so we say it is a 4-vector.</p>
<h3 id="elements-of-a-vector">Elements of a vector</h3>
<p>The elements in this case are real numbers so we can describe the vector as being a vector drawn from
<script type="math/tex">\mathbb{R}^4</script>
, the set of groups of 4 real numbers.</p>
<h3 id="relating-it-to-programming">Relating it to programming</h3>
<p>Since I’m a programmer I sometimes find it helps to think of things as a programmer might.</p>
<p>In this case let’s think of that age-old staple of computer programming, the list:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="p">[</span><span class="mi">12</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">11</span><span class="p">]</span></code></pre></figure>
<p>The “elements” of this list would be its consitituents:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="mi">12</span> <span class="mi">10</span> <span class="mi">15</span> <span class="mi">11</span></code></pre></figure>
<p>The “dimension” of this list would be the number of elements in it, in other words, its length:</p>
<figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="nb">len</span><span class="p">([</span><span class="mi">12</span><span class="p">,</span><span class="mi">10</span><span class="p">,</span><span class="mi">15</span><span class="p">,</span><span class="mi">11</span><span class="p">])</span> <span class="o">==</span> <span class="mi">4</span></code></pre></figure>
<h3 id="coming-up">Coming up</h3>
<p><a href="/articles/linalg-2">Next</a> we talk about things we can do with vectors such as adding them.</p>
<p><a href="http://chriscatalfo.com/articles/linalg-intro">Linear Algebra: a very very very short intro</a> was originally published by Chris Catalfo at <a href="http://chriscatalfo.com">chriscatalfo.com</a> on March 15, 2015.</p><![CDATA[Hello World]]>http://chriscatalfo.com/articles/hello-world2014-12-19T14:39:55-05:002014-12-19T14:39:55-05:00Chris Catalfohttp://chriscatalfo.comccatalfo@gmail.com<h2 id="if-everyone-else-went-and-jumped-off-a-bridge-wrote-a-blog-would-you">If everyone else went and <s>jumped off a bridge</s> wrote a blog would <em>you</em>?</h2>
<p><a href="http://chriscatalfo.com/articles/hello-world">Hello World</a> was originally published by Chris Catalfo at <a href="http://chriscatalfo.com">chriscatalfo.com</a> on December 19, 2014.</p>