Graphics, Figures & TablesIs there a package to create Horner Division diagram?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
fractal.generator
Posts: 66
Joined: Tue Oct 07, 2008 9:39 am

Is there a package to create Horner Division diagram?

Post by fractal.generator »

Dear all,

I am looking for a package to create Horner Division diagram as shown below :


Image

I have created it manually using the code snippet below.

Code: Select all

\documentclass{book}
\usepackage{pst-node,xcolor,graphicx,lipsum}
\pagestyle{empty}

\begin{document}
\lipsum[1]
\begin{figure}
\centering
\scalebox{0.8}{%
%\pspicture[showgrid=true](-1,-1)(10,7)
\psset{framesep=5pt,linecolor=blue}
\psframe[fillstyle=solid,fillcolor=blue!10](-0.4,1)(7.6,5.5)
$\psmatrix[colsep=10mm,rowsep=3mm,mnode=r,mcol=r]
%=========================================================
% MODIFY COEFFICIENTS
[mcol=c]\left(\ovalnode{ba2}{-2}\;x^2+\ovalnode{ba1}{0}\;x+\ovalnode{ba0}{7}\right)\div \left[\ovalnode{bmultiplier}{3}\left(x-\ovalnode{bzero}{-2}\right)\right]\psspan{7}\\% increment
%=========================================================
%NO MODIFICATION
&% col-1
[name=A]\\[0pt]% col-2
%=========================================================
% COEFFICIENTS
[name=ezero]-2&% Change the zero
&% ADD COEFFICIENTS AFTER THIS LINE
[name=ea2]-2&
[name=ea1]0&
[name=ea0]7\\
%=========================================================
&% col-1
&% col-2
&% col-3
&% col-4
&% col-5
[name=B]\\% col-6, ADD EMPTY BEFORE THIS LINE
%=========================================================
&% col-1
&% col-2
0&% col-3 always zero
[name=b1]4&% col-4	
[name=b0]-8\\[0pt]% col-5
%=========================================================
&% col-1
[name=C]+& % col-2
&% col-3
&% col-4
&% col-5
[name=D]\\[0pt]% col-6
&% col-1%
&% col-2
[name=c1]-2&% col-3
[name=c0]4&% col-4
[name=r]\psframebox[linecolor=black]{-1}&% col-5
&% col-6
[mcol=l]R(x)=\ovalnode{remainder}{-1}\\[0pt]% col-7 
%=========================================================
\psspan{7}\\[0pt]%increment
[mcol=l]\displaystyle Q(x)=\frac{\ovalnode{q1}{-2}\;x+\ovalnode{q0}{4}}{\ovalnode{emultiplier}{3}}\psspan{7}%increment
\endpsmatrix$
\ncangles[angleA=180,angleB=-90,arm=0pt,linestyle=dashed,linecolor=black]{A}{B}
\ncangles[angleA=0,angleB=180,arm=0pt,nodesepA=5pt,linecolor=black]{C}{D}
\psset{linecolor=blue,arrows=<-,nodesepA=5pt,nodesepB=0pt}
\ncbar[angleA=90,angleB=90,armA=10pt,linearc=1pt]{ezero}{bzero}
\ncangles[angleA=0,angleB=90,armA=8,armB=20pt,linearc=1pt,nodesepA=0pt]{emultiplier}{bmultiplier}
\ncarc{ea2}{ba2}
\ncarc{ea1}{ba1}
\ncarc{ea0}{ba0}
\psset{arrows=->,nodesep=5pt}
\ncarc[linecolor=black]{c1}{b1}
\ncarc[linecolor=black]{c0}{b0}
\psset{arrows=<-,nodesepB=5pt,nodesepA=0pt}
\ncbar[angle=90,arm=8pt,nodesep=0pt,linearc=1pt]{remainder}{r}
\ncarc{q1}{c1}
\ncarc{q0}{c0}
%\endpspicture%
}
\caption{by Hayashi}
\end{figure}
\lipsum[1]

\end{document}


Actually I want to create an environment with some arguments to which we pass the polynomial coefficients. The environment can do the corresponding arithmetic automatically as well.

I am a newbie in LaTeX's world, so if you have any idea to make it simpler, please let me know.



Thank you.


regards,

Hayashi

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
Knuffi
Posts: 25
Joined: Fri Oct 10, 2008 1:27 pm

Re: Is there a package to create Horner Division diagram?

Post by Knuffi »

Without the arrows and the circles, the package "polynom" should do it:

http://www.ctan.org/tex-archive/help/Ca ... lynom.html
Post Reply