3

I am trying to do a polynomial division using Horner's Method of Synthetic Division, as described on page 451 of the book, Elementary Algebra by Hall & Knight.

I wanted to perform the following division by the Horner's method:

Screenshot

I've managed to do this:

\documentclass{article}
\usepackage{arydshln}        
\begin{document}
    \begin{center}
        \begin{tabular}{r|rrr:rr}
            3 & 9 & 0 & 2 & 6 & -8   \\
            \hline
            -1 & & -3  & 6  & &      \\
             2 & &  &  1 & -2 &      \\
             & & &  & -3 &  6        \\
            \hline
             & 3 & -1  & 3  & 1 & -2 \\
            \cdashline{5-6}
        \end{tabular}
    \end{center}
\end{document}

But how can I draw the arrows as shown in the following picture?

Screenshot

Henri Menke
  • 109,596
Luo Kaisa
  • 227

2 Answers2

6

This is just a very quick answer.

\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{matrix,fit,arrows}
\begin{document}
    \begin{tikzpicture}[>=latex]
    \useasboundingbox (-5,-4) rectangle (5,4);
        \matrix (m) [row sep=1cm,column sep=1cm,matrix of nodes]
        {
            3 & 9  & 0 & 2 & 6 & -8 \\
            -1 & \phantom{a} & -3 & 6 & \phantom{a} & \phantom{a} \\
            2 & \phantom{a} & \phantom{a} & -1 & -2 & \phantom{a} \\
            \phantom{a} & \phantom{a} & \phantom{a} & \phantom{a} & -3 & 6 \\
            \phantom{a} & 3 & -1 & 3 & 1 & -2 \\
            \phantom{a} & $x^2$ & $x$ & T.I & $x$ & T.I \\
        };
        \draw ([xshift=.2cm]m-1-1.north east) -- ([xshift=.2cm]m-6-1.south east);
        \draw[dashed] ([yshift=.2cm]m-1-5.north east) -- ([yshift=.2cm]m-6-5.south east);
        \draw ([yshift=-.2cm]m-1-1.south west) -- ([yshift=-.2cm]m-1-6.south east);
        \draw ([yshift=-.2cm]m-4-1.south west) -- ([yshift=-.2cm]m-4-6.south east);
            \node[fit=(m-1-2),draw,circle,inner sep=1pt] (a) {};
            \node[draw,fit=(m-1-3)(m-2-3)] (b) {};
            \node[draw,fit=(m-1-4)(m-3-4)] (c) {};
        \draw[->] (a) --+ (0,-1.1) --+ (-.5,-.6);
        \draw[->] (b) --+ (0,-2) --+ (-.5,-1.5);
        \draw[->] (c) --+ (0,-3) --+ (-.5,-2.5);
    \end{tikzpicture}
\end{document}

Screenshot

current_user
  • 5,235
  • 1
    Instead of using \phantom{a} in empty cells, you could add nodes in empty cells to the matrix options, and you could consider using a matrix of math nodes instead of a matrix of nodes. Good use of fit! – Max Aug 28 '18 at 05:22
  • 1
    Well those "tips" weren't very helpful, were they? Sorry for my ignorance. – Max Aug 28 '18 at 09:42
  • @Max: Thank you for your tips, I really appreciate them, but since I'm not working with TeXStudio anymore, I have to use TeXmaker now and I'm not very into it (see the_real_deal; I've got the same problem …). – current_user Aug 28 '18 at 13:49
3

This is actually an addition to the answer of current_user, because I placed a comment with some "tips" but after actually trying them myself they actually made placing the lines of the matrix harder.

The problem that I ran into was that I wanted to use the actual width of the column, and the actual height of the row to place the lines, but you still want to use the minimum size of the nodes for fitting nodes around them. To fix this, I added a new matrix style fixed matrix that places a fixed size node in the background of the cell, that sets the height of the row and the width of the column, and placing an additional node with the real contents on top of it (that should be smaller than the desired dimensions, otherwise it still wouldn't work). These nodes are named <matrix name>-<row num>-<column num>-o and <matrix name>-<row num>-<column num>-i where o and i denote outer and inner respectively.

With this I can easily draw the following:

enter image description here

With only this code:

\begin{tikzpicture}[>=latex]
    \matrix [fixed matrix] (l) 
    {
         3 &     9 &   0 &   2 &   6 &  -8 \\
        -1 &       &  -3 &   6 &     &     \\
         2 &       &     &  -1 &  -2 &     \\
           &       &     &     &  -3 &   6 \\
           &     3 &  -1 &   3 &   1 &  -2 \\
           & $x^2$ & $x$ & T.I & $x$ & T.I \\
    };

    \draw (l-1-1-o.north east) -- (l-6-1-o.south east);
    \draw[dashed] (l-1-5-o.north east) -- (l-6-5-o.south east);
    \draw (l-1-1-o.south west) -- (l-1-6-o.south east);
    \draw (l-4-1-o.south west) -- (l-4-6-o.south east);

    \node[fit=(l-1-2-i),draw,circle,inner sep=1pt] (a) {};
    \node[draw,fit=(l-1-3-i)(l-2-3-i)] (b) {};
    \node[draw,fit=(l-1-4-i)(l-3-4-i)] (c) {};

    \draw[->] (a.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
    \draw[->] (b.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
    \draw[->] (c.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
\end{tikzpicture}

Some additional functions are:

  • The fixed matrix style accepts an argument that can be used to:
    • set the style for the inner nodes with inner nodes={<style>}
    • set the style of the outer nodes with outer nodes={<style>}
    • set the row height with row height=<dimension> (default is 10mm)
    • set the column width with column width=<dimension> (default is 10mm)

Small downside, if you name the matrix before calling the fixed matrix style, you cannot refer to the individual nodes with your custom matrix name, but the default m is used as matrix name.

When changing the fixed matrix call in the previous code snippet to fixed matrix={row height=8mm,column width=8mm,inner nodes={draw=green,line width=1pt},outer nodes={dashed,draw=blue}} you can obtain the following image (just an example, definitely not a proposed improvement):

enter image description here

Complete code (many many thanks to current_user for his start on this):

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{fit}

\tikzset{
    fixed matrix/.cd,
        row height/.initial=10mm,
        column width/.initial=10mm,
        name/.initial=m,
        inner node style/.style={},
        outer node style/.style={},
        inner nodes/.code={\tikzset{fixed matrix/inner node style/.style={#1}}},
        outer nodes/.code={\tikzset{fixed matrix/outer node style/.style={#1}}},
}
\tikzset{
    fixed matrix/.style={
        inner sep=0pt,
        nodes={inner sep=0.333em},
        name/.forward to=/tikz/fixed matrix/name,
        execute at begin cell={
            \node[
                inner sep=0pt,
                minimum width=\pgfkeysvalueof{/tikz/fixed matrix/column width},
                minimum height=\pgfkeysvalueof{/tikz/fixed matrix/row height},
                fixed matrix/outer node style,
            ] (\pgfkeysvalueof{/tikz/fixed matrix/name}-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn-o){};
            \node[fixed matrix/inner node style] (\pgfkeysvalueof{/tikz/fixed matrix/name}-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn-i) \bgroup},
        execute at end cell={\egroup;},
        execute at empty cell={
            \node[
                inner sep=0pt,
                minimum width=\pgfkeysvalueof{/tikz/fixed matrix/column width},
                minimum height=\pgfkeysvalueof{/tikz/fixed matrix/row height},
                fixed matrix/outer node style,
            ] (\pgfkeysvalueof{/tikz/fixed matrix/name}-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn-o){};},
    },
    fixed matrix/.append code=\tikzset{fixed matrix/.cd,#1},
}

\begin{document}
    \begin{tikzpicture}[>=latex]
        \matrix [fixed matrix={row height=8mm,column width=8mm,inner nodes={draw=green,line width=1pt},outer nodes={dashed,draw=blue}}] (l) 
        {
             3 &     9 &   0 &   2 &   6 &  -8 \\
            -1 &       &  -3 &   6 &     &     \\
             2 &       &     &  -1 &  -2 &     \\
               &       &     &     &  -3 &   6 \\
               &     3 &  -1 &   3 &   1 &  -2 \\
               & $x^2$ & $x$ & T.I & $x$ & T.I \\
        };

        \draw (l-1-1-o.north east) -- (l-6-1-o.south east);
        \draw[dashed] (l-1-5-o.north east) -- (l-6-5-o.south east);
        \draw (l-1-1-o.south west) -- (l-1-6-o.south east);
        \draw (l-4-1-o.south west) -- (l-4-6-o.south east);

        \node[fit=(l-1-2-i),draw,circle,inner sep=1pt] (a) {};
        \node[draw,fit=(l-1-3-i)(l-2-3-i)] (b) {};
        \node[draw,fit=(l-1-4-i)(l-3-4-i)] (c) {};

        \draw[->] (a.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
        \draw[->] (b.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
        \draw[->] (c.south) --++ (0,-0.6) node[right]{$ \div $} --+ (-0.4,0.4);
    \end{tikzpicture}
\end{document}
Max
  • 9,733
  • 3
  • 28
  • 35