Debian Codegraph @

texmf-dist/doc/latex/pstricks_calcnotes/For_Pdf_Output/ThreeAppsPDF.tex

raw
1 \documentclass[11pt,a4paper,oneside]{article}
2 \usepackage{calculator}
3 \usepackage{calculus}
4 \usepackage{amsthm}
5 \usepackage{amsmath}
6 \usepackage{cmtt}
7 \usepackage[dvips]{geometry}
8 \usepackage{pstricks}
9 \usepackage{graphicx}
10 \usepackage{graphics}
11 \usepackage{pst-plot}
12 \usepackage{pst-node}
13 \usepackage{multido}
14 \usepackage{pst-xkey}
15 \usepackage{pst-func}
16 \usepackage{pstricks-add}
17 \usepackage[pdftex,colorlinks,linktocpage]{hyperref}
18 \def\hantt{\^e}\def\accentcircflx{\hskip-.3em\raisebox{0.32ex}{\'{}}}
19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20 \def\RiemannSum#1#2#3#4#5#6#7#8#9{%
21 \psplot[linecolor=blue]{#1}{#2}{#3}
22 \pscustom[linecolor=red]{%
23 \psline{-}(#1,0)(#1,0)
24 \multido{\ni=#5,\ne=#6}{#4}
25 {\psline(*{\ni} {#8})(*{\ne} {#9})}}
26 \multido{\ne=#6,\nc=#7}{#4}
27 {\psdot(*{\nc} {#3})
28 \psline[linestyle=dotted,dotsep=1.5pt](\nc,0)(*{\nc} {#3})
29 \psline[linecolor=red](\ne,0)(*{\ne} {#9})}
30 }
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 \newcount\Fa\newcount\Fct\newcount\tempA
33 \def\Factor{\ifnum\Fa=1\relax\else\advance\Fa by -1\multiply\Fct by \Fa\Factor\fi}
34 \def\FACTORIAL#1{\Fa=#1 \ifnum\Fa=0 \Fct=1\relax\else\Fct=\Fa \Factor\fi\global\tempA=\Fct}
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 \newcount\BINOM
37 \newcount\temp
38 \newcount\tmp
39 \def\BINOMIAL#1#2{%
40 \temp=#1\advance\temp by -#2
41 \FACTORIAL{#1}
42 \tmp=\tempA
43 \FACTORIAL{\temp}
44 \temp=\tempA
45 \divide\tmp by \temp
46 \FACTORIAL{#2}
47 \temp=\tempA
48 \divide\tmp by \temp\global\BINOM=\tmp}
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 \newdimen\Xa\newdimen\Yb\newcount\kc
51 \newdimen\BSTemp
52 \def\xmult#1{\ifnum\kc<#1\advance\kc by 1\Yb=\decimal\Xa\Yb\xmult{#1}\else\relax\fi}
53 \def\BERNSTEIN#1#2#3{\Xa=#3pt\kc=0\Yb=1pt\xmult{#1}\kc=0\Xa=-\Xa\advance\Xa by 1pt\xmult{#2}
54 \BINOMIAL{6}{#1}\global\BSTemp=\BINOM\Yb}
55 \newdimen\Xrf\newdimen\Yrf
56 \newdimen\XBST\newdimen\YBST
57 \def\XBC#1#2#3{%
58 \BERNSTEIN{0}{6}{#2}
59 \Xrf=#1pt
60 \XBST=\decimal\BSTemp\Xrf
61 \BERNSTEIN{1}{5}{#2}
62 \Xrf=#1pt\advance\Xrf by -1.5pt
63 \advance\XBST by \decimal\BSTemp\Xrf
64 \BERNSTEIN{2}{4}{#2}
65 \Xrf=#1pt\advance\Xrf by 2pt
66 \advance\XBST by \decimal\BSTemp\Xrf
67 \BERNSTEIN{3}{3}{#2}
68 \Xrf=#1pt\advance\Xrf by 6pt
69 \advance\XBST by \decimal\BSTemp\Xrf
70 \BERNSTEIN{4}{2}{#2}
71 \Xrf=#1pt\advance\Xrf by 5pt
72 \advance\XBST by \decimal\BSTemp\Xrf
73 \BERNSTEIN{5}{1}{#2}
74 \Xrf=#1pt\advance\Xrf by 1.5pt
75 \advance\XBST by \decimal\BSTemp\Xrf
76 \BERNSTEIN{6}{0}{#2}
77 \Xrf=#1pt
78 \advance\XBST by \decimal\BSTemp\Xrf
79 \global\XBST=#3\XBST}
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 \def\YBC#1#2#3{%
82 \BERNSTEIN{0}{6}{#2}
83 \Yrf=#1pt
84 \YBST=\decimal\BSTemp\Yrf
85 \BERNSTEIN{1}{5}{#2}
86 \Yrf=#1pt\advance\Yrf by 2pt
87 \advance\YBST by \decimal\BSTemp\Yrf
88 \BERNSTEIN{2}{4}{#2}
89 \Yrf=#1pt\advance\Yrf by 5pt
90 \advance\YBST by \decimal\BSTemp\Yrf
91 \BERNSTEIN{3}{3}{#2}
92 \Yrf=#1pt\advance\Yrf by 3pt
93 \advance\YBST by \decimal\BSTemp\Yrf
94 \BERNSTEIN{4}{2}{#2}
95 \Yrf=#1pt\advance\Yrf by -1pt
96 \advance\YBST by \decimal\BSTemp\Yrf
97 \BERNSTEIN{5}{1}{#2}
98 \Yrf=#1pt\advance\Yrf by -2pt
99 \advance\YBST by \decimal\BSTemp\Yrf
100 \BERNSTEIN{6}{0}{#2}
101 \Yrf=#1pt
102 \advance\YBST by \decimal\BSTemp\Yrf
103 \global\YBST=#3\YBST}
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 \def\XBsix#1#2{%
106 (1-t)^6*(#1)*(#2)+6*t*(1-t)^5*(#1-1.5)*(#2)+15*t^2*(1-t)^4*(#1+2)*(#2)+
107 20*t^3*(1-t)^3*(#1+6)*(#2)+15*t^4*(1-t)^2*(#1+5)*(#2)+6*t^5*(1-t)*(#1+1.5)*(#2)+t^6*(#1)*(#2)}
108 \def\YBsix#1#2{%
109 (1-t)^6*(#1)*(#2)+6*t*(1-t)^5*(#1+2)*(#2)+15*t^2*(1-t)^4*(#1+5)*(#2)+
110 20*t^3*(1-t)^3*(#1+3)*(#2)+15*t^4*(1-t)^2*(#1-1)*(#2)+6*t^5*(1-t)*(#1-2)*(#2)+t^6*(#1)*(#2)}
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 \def\NetDraw#1#2#3#4#5{%
113 \newcount\CellNum
114 \newdimen\XRef
115 \newdimen\YRef
116 \newdimen\Xfact
117 \newdimen\Yfact
118 \newdimen\XMin
119 \newdimen\XMax
120 \newdimen\YMin
121 \newdimen\YMax
122 \newdimen\Xsize
123 \newdimen\Ysize
124 \newdimen\tempx
125 \newdimen\tempy
126 \CellNum=#1
127 \XRef=#2pt
128 \YRef=#3pt
129 \Xfact=#4pt
130 \Yfact=#5pt
131 \XMin=\decimal\Xfact\XRef \advance\XMin by -1.50\Xfact
132 \XMax=\decimal\Xfact\XRef \advance\XMax by 5.00\Xfact
133 \YMin=\decimal\Yfact\YRef \advance\YMin by -6.00\Yfact
134 \YMax=\decimal\Yfact\YRef \advance\YMax by \Yfact
135 \Xsize=\XMax \advance\Xsize by -\XMin \divide\Xsize by \CellNum
136 \Ysize=\YMax \advance\Ysize by -\YMin \divide\Ysize by \CellNum
137 \parametricplot[algebraic,fillstyle=solid,fillcolor=yellow!30,plotpoints=200,linewidth=0.5pt]{0}{0.5}
138 {\XBeight{\decimal\XRef}{\decimal\Xfact}|\YBeight{\decimal\YRef}{\decimal\Yfact}}
139 \parametricplot[algebraic,fillstyle=solid,fillcolor=yellow!30,plotpoints=200,linewidth=0.5pt]{0.5}{1}
140 {\XBeight{\decimal\XRef}{\decimal\Xfact}|\YBeight{\decimal\YRef}{\decimal\Yfact}}
141 \multido{\nz=0.00+0.05}{200}{\XBC{\decimal\XRef}{\nz}{\decimal\Xfact}\YBC{\decimal\YRef}{\nz}{\decimal\Yfact}
142 \multido{\nx=\decimal\XMin+\decimal\Xsize}{\the\CellNum}
143 {\tempx=\nx pt\multido{\ny=\decimal\YMin+\decimal\Ysize}{\the\CellNum}
144 {\tempy=\ny pt\ifdim\YBST<\tempy\relax\else\advance\tempy by \Ysize%
145 \ifdim\YBST>\tempy\relax\else
146 \ifdim\XBST<\tempx\relax\else\advance\tempx by \Xsize
147 \ifdim\XBST>\tempx\relax\else
148 \pspolygon[fillstyle=solid,fillcolor=red!90,linecolor=black,linewidth=0.2pt]
149 (\nx,\ny)(\decimal\tempx,\ny)(\decimal\tempx,\decimal\tempy)(\nx,\decimal\tempy)(\nx,\ny)\relax\fi\fi\fi\fi}
150 }}
151 \advance\CellNum by 1
152 \multido{\nx=\decimal\XMin+\decimal\Xsize}{\the\CellNum}
153 {\psline[linewidth=0.2pt](\nx,\decimal\YMax)(\nx,\decimal\YMin)}
154 \multido{\ny=\decimal\YMin+\decimal\Ysize}{\the\CellNum}
155 {\psline[linewidth=0.2pt](\decimal\XMin,\ny)(\decimal\XMax,\ny)}
156 \parametricplot[algebraic,linecolor=white,plotpoints=200,linewidth=0.5pt]{0}{0.5}
157 {\XBeight{\decimal\XRef}{\decimal\Xfact}|\YBeight{\decimal\YRef}{\decimal\Yfact}}
158 \parametricplot[algebraic,linecolor=white,plotpoints=200,linewidth=0.5pt]{0.5}{1}
159 {\XBeight{\decimal\XRef}{\decimal\Xfact}|\YBeight{\decimal\YRef}{\decimal\Yfact}}
160 }
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 \def\avecfld#1#2#3#4#5#6{%
163 \multido{#2}{#4}
164 {\multido{#1}{#3}
165 {\parametricplot[algebraic,arrows=->,linecolor=red]{0}{1}
166 {\nx+((#5)*t)*(1/sqrt(1+(#6)^2))|\ny+((#5)*t)*(1/sqrt(1+(#6)^2))*(#6)}}}}
167 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 \def\anothervecfld#1#2#3#4#5#6{%
169 \multido{#2}{#4}
170 {\multido{#1}{#3}
171 {\curvepnodes[algebraic,plotpoints=2]{0}{1}
172 {\nx+((#5)*t)*(1/sqrt(1+(#6)^2))|\ny+((#5)*t)*(1/sqrt(1+(#6)^2))*(#6)}{P}
173 \psline[linewidth=0.7pt,linecolor=red]{->}(P0)(P1)}}}
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 \def\xch{\catcode`\p=12 \catcode`\t=12}\def\ych{\catcode`\p=11 \catcode`\t=11}
176 \xch \def\dec#1pt{#1}\ych \def\decimal#1{\expandafter\dec \the#1}
177 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 \def\vecfldnew#1#2#3#4#5#6#7#8{%
179 \newcount\intg \newdimen\fx \newdimen\fy \newdimen\slope \newdimen\interm
180 \def\fintg{\interm=#8 \interm=\intg\interm \ifdim\ifdim\slope<0pt-\fi\slope<\interm\advance\intg by -1\relax\else\advance\intg by 1\fintg\fi}
181 \multido{#2}{#4}
182 {\multido{#1}{#3}
183 {\curvepnodes[algebraic,plotpoints=2]{0}{1}{\nx+((#5)*t)*(1/sqrt(1+(#6)^2))|\ny+((#5)*t)*(1/sqrt(1+(#6)^2))*(#6)}{P}
184 #7 \slope=10\slope\fintg
185 \ifnum\intg>10\psline[linecolor=red]{->}(P0)(P1)\else\ifnum\intg=0\psline[linecolor=red!5]{->}(P0)(P1)\else\multiply\intg by 10
186 \psline[linecolor=red!\the\intg]{->}(P0)(P1)\fi\fi
187 \intg=0\slope=0pt
188 }}}
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190 \pagestyle{headings}
191 \topmargin=-0.6cm
192 \textwidth=16.7cm
193 \textheight=23cm
194 \headheight=2.5ex
195 \headsep=0.6cm
196 \oddsidemargin=.cm
197 \evensidemargin=-.4cm
198 \parskip=0.7ex plus0.5ex minus 0.5ex
199 \baselineskip=17pt plus2pt minus2pt
200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 \catcode`@=11
202 \renewcommand\section{\@startsection {section}{1}{\z@}%
203 {-3.5ex \@plus -1ex \@minus -.2ex}%
204 {2.3ex \@plus.2ex}%
205 {\normalfont\large\bfseries}}
206 \renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
207 {-3.25ex\@plus -1ex \@minus -.2ex}%
208 {1.5ex \@plus .2ex}%
209 {\normalfont\normalsize\bfseries}}
210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211 \gdef\acknw{\section*{%
212 {\acknwname}\markright{\protect\textsl{\acknwname}}}%
213 \addcontentsline{toc}{section}{\acknwname}}
214 \gdef\acknwname{Acknowledgment}
215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216 \renewcommand\sectionmark[1]{\markright{\thesection. #1}}
217 \newcounter{lk}
218 \newenvironment{listof}{\begin{list}{\rm(\roman{lk})}{\usecounter{lk}%
219 \setlength{\topsep}{0ex plus0.1ex}%
220 \setlength{\labelwidth}{1cm}%
221 \setlength{\itemsep}{0ex plus0.1ex}%
222 \setlength{\itemindent}{0.5cm}%
223 }}{\end{list}}
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225 \title{Three applications of macros in \texttt{PSTricks}\thanks{PSTricks is the original work of Timothy Van Zandt (email address: \texttt{[email protected]}).
226 It is currently edited by Herbert Vo\ss\ (\texttt{[email protected]}).}}
227 \author{Le Phuong Quan\\
228 \small{(Cantho University, Vietnam)}\\
229 \small{\texttt{[email protected]}}}
230 \begin{document}
231 \maketitle
232 \tableofcontents
233 \section{Drawing approximations to the area under a graph by rectangles}
234 \subsection{Description}
235
236 We recall here an operation in Calculus. Let $f(x)$ be a function, defined and bounded on
237 an interval $[a,b]$. If $f$ is integrable (in Riemann sense) on $[a,b]$, then its definite integral over this interval
238 is
239 $$\int_a^bf(x)dx=\lim_{\|P\|\to 0}\sum_{i=1}^nf(\xi_i)\Delta x_i,$$
240 where $P\colon a=x_0<x_1<\cdots<x_n=b$, $\Delta x_i=x_i-x_{i-1}$ is a partition of $[a,b]$, $\xi_i\in[x_{i-1},x_i]$, $i=1,2,\ldots,n$,
241 and $\|P\|=\max\{\Delta x_i\colon i=1,2,\ldots,n\}$. Hence, when $\|P\|$ is small enough, we may have an
242 approximation
243 \begin{equation}\label{eqn1}
244 I=\int_a^bf(x)dx\approx\sum_{i=1}^nf(\xi_i)\Delta x_i.
245 \end{equation}
246 Because $I$ is independent to the choice of $P$ and $\xi_i$, we may
247 divide $[a,b]$ into $n$ subintervals with equal length and choose $\xi_i=(x_i+x_{i-1})/2$.
248 Then, $I$ can be approximately seen as the sum of areas of the rectangles with sides
249 $f(\xi_i)$ and $\Delta x_i$.
250
251 We will make a drawing procedure to illustrate the approximation (\ref{eqn1}). Firstly, we establish
252 commands to draw the ``sum'' of rectangles, like the area under piecewise-constant functions
253 (called \textsl{step shape\/}, for brevity). The chosen procedure here
254 obviously includes a combination of the macros \texttt{\symbol{92}pscustom} (to \textsl{join\/} horizontal segments, automatically)
255 and \texttt{\symbol{92}multido}. In particular, horizontal segments are depicted within the loop
256 \texttt{\symbol{92}multido} by
257 $$\textmtt{\symbol{92}psplot[{\it settings}]\{$x_{i-1}$\}\{$x_i$\}\{$f(\xi_i)$\}}$$
258 Then, \texttt{\symbol{92}pscustom} will join these segments altogether with the ending points
259 $(a,0)$, $(b,0)$ to make the boundary of the step shape. Next, we draw the points $(\xi_i,f(\xi_i))$, $i=1,2,\ldots,n$,
260 and the dotted segments between these points and the points $(\xi_i,0)$, $i=1,2,\ldots,n$, by
261 \begin{align*}
262 &\textmtt{\symbol{92}psdot[algebraic,\dots](*\{$\xi_i$\} \{$f(x)$\})}\\
263 &\textmtt{\symbol{92}psline[algebraic,linestyle=dotted,\dots]($\xi_i$,$0$)(*\{$\xi_i$\} \{$f(x)$\})}
264 \end{align*}
265 where we use the structure \textmtt{(*\{{\it value}\} \{$f(x)$\})} to obtain $(\xi_i,f(\xi_i))$. Finally, we draw
266 vertical segments to split the step shape into rectangular cells by
267 $$\textmtt{\symbol{92}psline[algebraic,\dots]($x_i$,$0$)(*\{$x_i$\} \{$f(x-\Delta x_i/2)$\})}$$
268 The process of approximation is depicted in Figure \ref{Fig1}.
269 \begin{figure}[htbp]
270 \centering\includegraphics[height=5.5cm]{Fig1a}
271 \hskip3em\includegraphics[height=5.5cm]{Fig1b}\\[2ex]
272 \centering\includegraphics[height=5cm]{Fig1c}
273 \caption{Steps to make the drawing procedure.}\label{Fig1}
274 \end{figure}
275
276 We now combine the above steps to make a procedure whose calling sequence consists of main parameters
277 $a$, $b$, $f$ and $n$, and dependent parameters $x_{i-1}$, $x_i$, $\xi_i$, $f(\xi_i)$ and
278 $f(x\pm\Delta x_i/2)$. For instance, let us consider approximations to the integral of $f(x)=\sin x-\cos x$
279 over $[-2,3]$ in cases of $n=5$ and $n=20$. They are given in Figure \ref{Fig2}.
280 \begin{figure}[htbp]
281 \centering\includegraphics[height=6.1cm]{Fig2a}
282 \hskip4em\includegraphics[height=6.1cm]{Fig2b}
283 \caption{Approximations to the integral of $f(x)=\sin x-\cos x$ over $[-2,3]$.}\label{Fig2}
284 \end{figure}
285
286 In summary, we can make a procedure to illustrate the approximation (\ref{eqn1}), say \texttt{RiemannSum}, whose calling sequence has the form of
287 $$\textmtt{\symbol{92}RiemannSum\{$a$\}\{$b$\}\{$f(x)$\}\{$n$\}\{$x_{\rm ini}$\}\{$x_{\rm end}$\}\{$x_{\rm choice}$\}\{$f(x+\Delta x_i/2)$\}\{$f(x-\Delta x_i/2)$\}},$$
288 where $x_0=a$ and for each $i=1,2\ldots,n$:
289 \begin{align*}
290 x_i&=a+\dfrac{b-a}{n}i,\quad\Delta x_i=x_i-x_{i-1}=\dfrac{b-a}{n},\\
291 x_{\rm ini}&=x_0+\Delta x_i,\quad x_{\rm end}=x_1+\Delta x_i,\quad x_{\rm choice}=\dfrac{x_{\rm ini}+x_{\rm end}}{2}=\dfrac{x_0+x_1}{2}+\Delta x_i.
292 \end{align*}
293 Note that $x_{\rm ini}$, $x_{\rm end}$ and $x_{\rm choice}$ are given in such forms to be
294 suitable to variable declaration in \texttt{\symbol{92}multido}. They are nothing but
295 $x_{i-1}$, $x_i$ and $\xi_i$, respectively, at the step $i$-th in the loop.
296
297 Tentatively, in \texttt{PSTricks} language, the definition of \texttt{RiemannSum} is suggested to be
298 \bigskip\hrule
299 \noindent\begin{tabular}{@{}l}
300 \verb!\def\RiemannSum#1#2#3#4#5#6#7#8#9{%!\\
301 \verb!\psplot[linecolor=blue]{#1}{#2}{#3}!\\
302 \verb!\pscustom[linecolor=red]{%!\\
303 \verb!\psline{-}(#1,0)(#1,0)!\\
304 \verb!\multido{\ni=#5,\ne=#6}{#4}!\\
305 \verb!{\psline(*{\ni} {#8})(*{\ne} {#9})}}!\\
306 \verb!\multido{\ne=#6,\nc=#7}{#4}!\\
307 \verb!{\psdot(*{\nc} {#3})!\\
308 \verb!\psline[linestyle=dotted,dotsep=1.5pt](\nc,0)(*{\nc} {#3})!\\
309 \verb!\psline[linecolor=red](\ne,0)(*{\ne} {#9})}}!
310 \end{tabular}\hrule
311 \subsection{Examples}
312 We give here two more examples just to see that using the drawing procedure is very easy. In the first example, we approximate
313 the area under the graph of the function $f(x)=x-(x/2)\cos x+2$ on the interval $[0,8]$. To draw the approximation, we try
314 the case $n=16$; thus $x_0=0$ and for each $i=1,\ldots,16$, we have
315 $x_i=0.5\,i$, $\Delta x_i=0.5$, $x_{\rm ini}=0.00+0.50$, $x_{\rm end}=0.50+0.50$ and $x_{\rm choice}=0.25+0.50$.
316 \begin{figure}[htbp]
317 \centering\includegraphics[height=6.6cm]{Fig3}
318 \vskip0.5ex
319 \caption{An approximation to the area under the graph of $f(x)=x-(x/2)\cos x+2$ on $[0,8]$.}\label{Fig3}
320 \end{figure}
321
322 To get Figure \ref{Fig3}, we have used the following \LaTeX\ code:
323 \bigskip\hrule
324 \noindent\begin{tabular}{@{}l}
325 \verb!\begin{pspicture}(0,0)(4.125,5.5)!\\
326 \verb!\psset{plotpoints=500,algebraic,dotsize=2.5pt,unit=0.5}!\\
327 \verb!\RiemannSum{0}{8}{x-(x/2)*cos(x)+2}{16}{0.00+0.50}{0.50+0.50}{0.25+0.50}!\\
328 \verb!{x+0.25-((x+0.25)/2)*cos(x+0.25)+2}{x-0.25-((x-0.25)/2)*cos(x-0.25)+2}!\\
329 \verb!\psaxes[ticksize=2.2pt,labelsep=4pt]{->}(0,0)(8.5,11)!\\
330 \verb!\end{pspicture}!
331 \end{tabular}\hrule\bigskip
332
333 In the second example below, we will draw an approximation to the integral of $f(x)=x\sin x$ over $[1,9]$.
334 Choosing $n=10$ and computing parameters needed, we get Figure \ref{Fig4}, mainly by
335 the command
336 \begin{align*}
337 &\textmtt{\symbol{92}RiemannSum\{$1$\}\{$9$\}\{$x\sin x$\}\{$10$\}\{$1.00+0.80$\}\{$1.80+0.80$\}\{$1.40+0.80$\}}\\
338 &\textmtt{\{$(x+0.4)\sin(x+0.4)$\}\{$(x-0.4)\sin(x-0.4)$\}}
339 \end{align*}
340 in the drawing procedure.
341 \begin{figure}[htbp]
342 \centering\includegraphics[height=6.75cm]{Fig4}
343 \caption{An approximation to the integral of $f(x)=x\sin x$ over $[1,9]$.}\label{Fig4}
344 \end{figure}
345 \section{Drawing the vector field of an ordinary differential equation of order one}
346 \subsection{Description}\label{sect1}
347
348 Let us consider the differential equation
349 \begin{equation}\label{eqn2}
350 \frac{dy}{dx}=f(x,y).
351 \end{equation}
352 At each point $(x_0,y_0)$ in the domain $D$ of $f$, we will put a vector $\mathbf{v}$ with slope
353 $k=f(x_0,y_0)$. If $y(x_0)=y_0$, then $k$ is the slope of the tangent to the solution curve $y=y(x)$
354 of (\ref{eqn2}) at $(x_0,y_0)$. The $\mathbf{v}$'s make a \textsl{vector field\/} and the picture
355 of this field would give us information about the shape of solution curves of (\ref{eqn2}), even
356 we have not found yet any solution of (\ref{eqn2}).
357
358 The vector field of (\ref{eqn2}) will be depicted on a finite grid of points in $D$. This grid is made of
359 lines, paralell to the axes $Ox$ and $Oy$. The intersectional points of those lines are called \textsl{grid points\/}
360 and often indexed by $(x_i,y_j)$, $i=0,\ldots,N_x$, $j=0,\ldots,N_y$. For convenience, we will use
361 polar coordinates to locate the terminal point $(x,y)$ of a field vector, with the initial point at
362 grid point $(x_i,y_j)$. Then, we can write
363 \begin{align*}
364 x&=x_i+r\cos\varphi,\\
365 y&=y_j+r\sin\varphi.
366 \end{align*}
367 Because $k=f(x_i,y_j)=\tan\varphi$ is finite, we may take $-\pi/2<\varphi<\pi/2$.
368 From $\sin^2\varphi+\cos^2\varphi=1$ and $\sin\varphi=k\cos\varphi$, we derive
369 $$\cos\varphi=\frac{1}{\sqrt{1+k^2}},\quad\sin\varphi=\frac{k}{\sqrt{1+k^2}}.$$
370 \begin{figure}[htbp]
371 \centering\includegraphics[height=5cm]{Fig5}
372 \caption{Field vectors on a grid.}\label{Fig5}
373 \end{figure}
374 The field vectors should all have the same magnitude and we choose here that length to be
375 $1/2$, that means $r=1/2$. Thus, vectors on the grid have their initial and terminal points as
376 $$(x_i,y_j),\quad \Big(x_i+\frac{1}{2}\cos\varphi,y_j+\frac{1}{2}\sin\varphi\Big),$$
377 respectively. Hence, we easily get the parametrization of a vector at grid point
378 $(x_i,y_j)$:
379 \begin{align*}
380 x&=x_i+\frac{t}{2}\cos\varphi=x_i+\frac{t}{2\sqrt{1+k^2}},\\
381 y&=y_j+\frac{t}{2}\sin\varphi=y_j+\frac{tk}{2\sqrt{1+k^2}},
382 \end{align*}
383 where $t$ goes from $0$ to $1$, as along the direction of the vector.
384
385 Of macros in \texttt{PSTricks} to draw lines from their parametrization, we select \texttt{\symbol{92}parametricplot}\footnote{\footnotesize
386 This macro is of ones, often added and updated in the package \texttt{pstricks-add}, the authors:
387 Dominique Rodriguez (\texttt{[email protected]}), Herbert Vo\ss\ (\texttt{[email protected]}).}
388 for its fitness. The macro has the syntax
389 $$\textmtt{\symbol{92}parametricplot[{\it settings}]\{$t_{\rm min}$\}\{$t_{\rm max}$\}\{$x(t)$|$y(t)$\}},$$
390 where we may use the option \texttt{algebraic} to make the declaration of $x(t)$ and $y(t)$ simpler
391 in \texttt{ASCII} code.
392
393 From the above description of one field vector, we now construct the vector field
394 on a grid within a domain $R=\{(x,y)\colon a\le x\le b,\,c\le y\le d\}$. To determine the grid, we confine grid points to the range
395 \begin{equation}\label{eqn3}
396 a\le x_i\le b,\quad c\le y_j\le d.
397 \end{equation}
398 We start with initial values $x_0=a$ and $y_0=c$ to have points $(x_i,y_j)$ with increments $\Delta x=\Delta y=\delta$, corresponding to the length of vectors and the distance
399 between grid points as indicated in Figure \ref{Fig5}. Thus, to draw vectors at grid points
400 $(x_i,y_j)$, we need two loops for indices $i$ and $j$, with $0\le i\le\lfloor m/\delta\rfloor$, $0\le j\le\lfloor n/\delta\rfloor$, where
401 $m=b-a$, $n=d-c$. Apparently, these two loops are nested \texttt{\symbol{92}multido}s, with variable declaration
402 for each loop as follows
403 \begin{align*}
404 \texttt{\symbol{92}nx}&=\text{initial value}+\text{increment}=x_0+\Delta x,\\
405 \texttt{\symbol{92}ny}&=\text{initial value}+\text{increment}=y_0+\Delta y.
406 \end{align*}
407 Finally, we will replace \texttt{\symbol{92}nx}, \texttt{\symbol{92}ny} by $x_i$, $y_j$ in the
408 below calling sequence for simplicity.
409
410 Thus, the main command to draw the vector field of the equation (\ref{eqn2}) on the grid (\ref{eqn3})
411 is
412 \begin{align*}
413 &\textmtt{\symbol{92}multido\big\{$y_j=y_0+\Delta y$\big\}\big\{$\lfloor n/\delta\rfloor$\big\}}\textmtt{\bigg\{\symbol{92}multido\big\{$x_i=x_0+\Delta x$\big\}\big\{$\lfloor m/\delta\rfloor$\big\}}\\
414 &\quad\textmtt{\Big\{\symbol{92}parametricplot[{\it settings}]\{$0$\}\{$1$\}\Big\{$x_i+\frac{t}{2\sqrt{1+\big[f(x_i,y_j)\big]^2}}$\Big|
415 $y_j+\frac{tf(x_i,y_j)}{2\sqrt{1+\big[f(x_i,y_j)\big]^2}}$\Big\}\bigg\}}
416 \end{align*}
417 where we at least use \texttt{arrows=->} and \texttt{algebraic} for \textit{settings}.
418
419 We can combine the steps mentioned above to define a drawing procedure, say \texttt{\symbol{92}avecfld},
420 that consists of $6$ parameters in the order as
421 \texttt{\symbol{92}nx=}$x_0+\Delta x$, \texttt{\symbol{92}ny=}$y_0+\Delta y$, $\lfloor m/\delta\rfloor$, $\lfloor n/\delta\rfloor$, $\delta$
422 and $f(\texttt{\symbol{92}nx},\texttt{\symbol{92}ny})$. We may change these values to modify
423 the vector field or to avoid the vector intersection. Such a procedure is suggested to be
424 \bigskip\hrule
425 \noindent\begin{tabular}{@{}l}
426 \verb!\def\avecfld#1#2#3#4#5#6{%!\\
427 \verb!\multido{#2}{#4}{\multido{#1}{#3}!\\
428 \verb!{\parametricplot[algebraic,arrows=->,linecolor=red]{0}{1}!\\
429 \verb!{\nx+((#5)*t)*(1/sqrt(1+(#6)^2))|\ny+((#5)*t)*(1/sqrt(1+(#6)^2))*(#6)}}}}!
430 \end{tabular}\hrule\bigskip
431
432 Actually, the procedure \texttt{\symbol{92}parametricplot} is used here only to draw a vector by its parametrization $(x(t),y(t))$, so we can use the structure \texttt{\symbol{92}curvepnodes} in the package \texttt{pst-node}\footnote{\footnotesize
433 Package authors: Timothy Van Zandt (\texttt{[email protected]}), Michael Sharpe (\texttt{[email protected]}) and Herbert Vo\ss\ (\texttt{[email protected]}).} to
434 extract the two ending points of the curve $(x(t),y(t))$ by the command
435 $$\textmtt{\symbol{92}curvepnodes[algebraic,plotpoints=2]\{0\}\{1\}\{$x(t)$|$y(t)$\}\{P\}},$$
436 where \texttt{P} is a name of the root of nodes and we just get the two nodes \texttt{P0}, \texttt{P1} when executing this command. Then, the corresponding
437 vector is drawn by the command
438 $$\textmtt{\symbol{92}psline[linecolor={\it settings}]\{->\}(P0)(P1)}$$
439
440 Therefore, another procedure to draw a vector field may be defined as
441 \bigskip\hrule
442 \noindent\begin{tabular}{@{}l}
443 \verb!\def\anothervecfld#1#2#3#4#5#6{%!\\
444 \verb!\multido{#2}{#4}{\multido{#1}{#3}!\\
445 \verb!{\curvepnodes[algebraic,plotpoints=2]{0}{1}!\\
446 \verb!{\nx+((#5)*t)*(1/sqrt(1+(#6)^2))|\ny+((#5)*t)*(1/sqrt(1+(#6)^2))*(#6)}{P}!\\
447 \verb!\psline[linecolor=red]{->}(P0)(P1)}}}!
448 \end{tabular}\hrule
449 \subsection{Examples}
450 Firstly, we consider the equation that describes an object falling in a resistive medium:
451 \begin{equation}\label{eqn4}
452 \frac{dv}{dt}=9.8-\frac{v}{5},
453 \end{equation}
454 where $v=v(t)$ is the speed of the object in time $t$. In Figure \ref{Fig6}, the vector field of (\ref{eqn4}) is given
455 on the grid $R=\{(t,y)\colon 0\le t\le 9,\,46\le v\le 52\}$, together with the graph of the equilibrium solution
456 $v=49$.
457 \begin{figure}[htbp]
458 \centering\includegraphics[height=5.85cm]{Fig6}
459 \caption{The vector field of (\ref{eqn4}).}\label{Fig6}
460 \end{figure}
461
462 Figure \ref{Fig6} is made of the following \LaTeX\ code:
463 \bigskip\hrule
464 \noindent\begin{tabular}{@{}l}
465 \verb!\begin{pspicture}(0,46)(9.5,52.5)!\\
466 \verb!\anothervecfld{\nx=0.25+0.50}{\ny=46.25+0.50}{18}{12}{0.5}{9.8-0.2*\ny}!\\
467 \verb!\psplot[algebraic,linewidth=1.2pt]{0}{9}{49}!\\
468 \verb!\psaxes[Dy=1,Dx=1,Oy=46]{->}(0,46)(0,46)(9.5,52.5)!\\
469 \verb!\rput(9.5,45.8){$t$}\rput(-0.2,52.5){$y$}!\\
470 \verb!\end{pspicture}!
471 \end{tabular}\hrule\bigskip
472
473 Let us next consider the problem
474 \begin{equation}\label{eqn5}
475 \frac{dy}{dx}=x+y,\quad y(0)=0.
476 \end{equation}
477 It is easy to check that $y=e^x-x-1$ is the unique solution to (\ref{eqn5}). We now draw
478 the vector field of (\ref{eqn5}) and the solution curve\footnote{\footnotesize
479 We have used ${\rm ch}(1)+{\rm sh}(1)$ for the declaration of $e$, natural base of logarithmic function.} on the grid $R=\{(x,y)\colon 0\le x\le 3,\,0\le y\le 5\}$ in
480 Figure \ref{Fig7}.
481 \begin{figure}[htbp]
482 \centering\includegraphics[height=5.5cm]{Fig7}
483 \caption{The vector field of (\ref{eqn5}).}\label{Fig7}
484 \end{figure}
485
486 We then go to the logistic equation, which is chosen to be a model for the dependence
487 of the population size $P$ on time $t$ in Biology:
488 \begin{equation}\label{eqn6}
489 \frac{dP}{dt}=kP\Big(1-\frac{P}{M}\Big),
490 \end{equation}
491 where $k$ and $M$ are constants, respectively various to selected species and environment.
492 For specification, we take, for instance, $k=0.5$ and $M=100$. The right hand side of
493 (\ref{eqn6}) then becomes $f(t,P)=0.5\,P(1-0.01\,P)$. In Figure \ref{Fig8}, we draw the vector field
494 of (\ref{eqn6}) on the grid $R=\{(t,P)\colon 0\le t\le 10,\,95\le P\le 100\}$ and the equilibrium
495 solution curve $P=100$. Furthermore, with the initial condition $P(0)=95$, the equation (\ref{eqn6})
496 has the unique solution $P=1900(e^{-0.5t}+19)^{-1}$. This solution curve is also given in Figure \ref{Fig8}.
497 \begin{figure}[htbp]
498 \centering\includegraphics[height=4.4cm]{Fig8}
499 \caption{The vector field of (\ref{eqn6}) with $k=0.5$ and $M=100$.}\label{Fig8}
500 \end{figure}
501
502 The previous differential equations are all of seperated variable or linear cases that
503 can be solved for closed-form solutions by some simple integration formulas. We will consider one more
504 equation of the non-linear case whose solution can only be approximated by numerical methods.
505 The vector field of such an equation is so useful and we will use the Runge-Kutta curves (of order $4$)
506 to add more information about the behaviour of solution curves. Here, those Runge-Kutta curves are depicted by the procedure
507 \texttt{\symbol{92}psplotDiffEqn}, also updated from the package \texttt{pstricks-add}.
508
509 The vector field of the non-linear differential equation
510 \begin{equation}\label{eqn7}
511 \frac{dy}{dx}=y^2-xy+1
512 \end{equation}
513 will be depicted on the grid $R=\{(x,y)\colon -3\le x\le 3,\,-3\le y\le 3\}$ and the solutions
514 of Cauchy problems for (\ref{eqn7}), corresponding to initial conditions
515 \begin{listof}
516 \item $y(-3)=-1$,
517 \item $y(-2)=-3$,
518 \item $y(-3)=-0.4$,
519 \end{listof}
520 will be approximated by the method of Runge-Kutta, with the grid size $h=0.2$. It is very easy
521 to recognize approximate curves, respective to (i), (ii) and (iii) in Figure \ref{Fig9} below.
522 \begin{figure}[htbp]
523 \centering\includegraphics[height=7.8cm]{Fig9}
524 \caption{The vector field of (\ref{eqn7}) and the Runge-Kutta curves.}\label{Fig9}
525 \end{figure}
526 \subsection{Remarks on how to color arrows properly for a vector field}
527 There remains a problem in drawing a vector field. That is coloring arrows.
528 Obviously, their color shade should vary according to their slope and this would give us the picture of domains containing
529 increase or decrease solutions of a differential equation. In some cases, we even know how large the rate of change of those
530 solutions is in a specific domain.
531
532 In Subsection \ref{sect1}, we know for the equation (\ref{eqn2}) that $f(x_i,y_j)$ is right the slope of
533 field vectors at grid points $(x_i,y_j)$, and we will divide these slopes into some number of scales, corresponding to the
534 degree of color shades. Here, we confine our interest to a continuous function $f(x,y)$ in two independent variables on a domain
535 $R=\{(x,y)\colon a\le x\le b,\,c\le y\le d\}$ and choose the scale of $10$ degrees. This number of degrees can be changed to any positive integer.
536
537 According to the input data from the differential equation (\ref{eqn2}), the set $R$ and the grid points on it and the value $M=\max\{|f(x_i,y_j)|\colon
538 0\le i\le\lfloor m/\Delta x\rfloor,\,0\le j\le\lfloor n/\Delta y\rfloor\}$, where $m=b-a$ and $n=d-c$,
539 we can now define the degree of color shade for each arrow in our vector field. It should be an integer $n_{ij}$ such that
540 $n_{ij}=\lfloor 10|f(x_i,y_j)|/M\rfloor$, that is
541 \begin{equation}\label{eqn8}n_{ij}M\le 10|f(x_i,y_j)|<(n_{ij}+1)M.\end{equation}
542 For finding such an integer, in \TeX\ codes, we need one \texttt{\symbol{92}newcount} for it and two \texttt{\symbol{92}newdimen} for
543 $f(x_i,y_j)$ and intermediate values to be compared with $|f(x_i,y_j)|$. For more explanation, let us begin with settings
544 \texttt{\symbol{92}newcount\symbol{92}intg} (referring (ref.) to ``integer''), \texttt{\symbol{92}newdimen\symbol{92}slope} (ref. to ``slope'') and \texttt{\symbol{92}newdimen\symbol{92}interm}
545 (ref. to ``intermediate values''). Then, the integer $n_{ij}$ at stage $(i,j)$ within the two \texttt{\symbol{92}multido} loops can be defined by the recursive macro \texttt{\symbol{92}fintg} (ref. to ``find the integer'') as follows
546 \begin{verbatim}
547 \def\fintg{\interm=Mpt \interm=\intg\interm%
548 \ifdim\ifdim\slope<0pt -\fi\slope<\interm\advance\intg by -1\relax
549 \else\advance\intg by 1\fintg\fi}
550 \end{verbatim}
551 where \texttt{M} and \texttt{\symbol{92}slope} are holding the values $M$ and $f(x_i,y_j)$, respectively. Note that, before running our macro, \verb!\slope! should be multiplied
552 by $10$ with the assignment \texttt{\symbol{92}slope=10\symbol{92}slope}, as defined in (\ref{eqn8}). Besides, by simulating the expression of $f(x,y)$, the calculation of $f(x_i,y_j)$
553 should be declared with operations on \texttt{\symbol{92}newcount}s and \texttt{\symbol{92}newdimen}s. Then, the integer $n_{ij}$, which is found at stage $(i,j)$, should take its
554 degree, say $k$, from $0$ to $10$ by its value, suitably associated to the command \textmtt{\symbol{92}psline[linecolor=red!case-k]\{->\}(P0)(P1)}.
555 Here, we choose \texttt{red} for the main color (it can be changed, of course), and \texttt{case-k} will be replaced with an appropriate percentage of \texttt{red}. Finally,
556 such a color scale is local and relative, so we can use one more parameter in the procedure to adjust color shades.
557 The old procedures take $6$ parameters and the new one will take two more parameters: one for declaration of computing $f(x_i,y_j)$ and the other
558 for adjusting color shades.
559
560 Let us take some examples on how to compute $f(x_i,y_j)$ by \TeX\ codes or by commands from the package \texttt{calculator}\footnote{\footnotesize
561 Package author: Robert Fuster (\texttt{[email protected]}).}. For a simple polynomial $f(x,y)$,
562 computing $f(x_i,y_j)$ by \TeX\ codes might be facile. Because \verb!\nx! and \verb!\ny! are respectively holding values of
563 $x_i$ and $y_j$, we need the two corresponding variables \verb!\newdimen\fx! and \verb!\newdimen\fy! to take these values. By assigning \verb!\fx=\nx pt\fy=\ny pt!,
564 we compute $f(\verb!\nx!,\verb!\ny!)$ and assign its value to \verb!\slope!. The declaration of calculations for some cases of $f(x,y)$ is given in the following table.
565
566 \begin{table}[htbp]
567 \centering\begin{tabular}{c|l}
568 $f(x,y)$&\multicolumn{1}{c}{\TeX\ codes for computing $f(\texttt{\symbol{92}nx},\texttt{\symbol{92}ny})$} \\ \hline
569 $x+y$&\verb!\advance\slope by \fx \advance\slope by \fy!\\ \hline
570 $1-xy$&\verb!\advance\slope by -\decimal\fx\fy \advance\slope by 1pt!\\ \hline
571 $y(3-y)$&\verb!\advance\slope by -\decimal\fy\fy \advance\slope by 3\fy!\\ \hline
572 $y^2-xy$&\verb!\advance\slope by \decimal\fy\fy \advance\slope by -\decimal\fx\fy!\\ \hline
573 \end{tabular}
574 \end{table}
575 In the table, the command \verb!\decimal!, which is quotative from \cite{five} for producing decimal numbers from dimensions, is put in the preamble using a definition as
576 \begin{verbatim}
577 \def\xch{\catcode`\p=12 \catcode`\t=12}\def\ych{\catcode`\p=11 \catcode`\t=11}
578 \xch \def\dec#1pt{#1}\ych \def\decimal#1{\expandafter\dec \the#1}
579 \end{verbatim}
580
581 For a transcendental or rational function $f(x,y)$, we may use the package \texttt{calculator} for
582 computing $f(x_i,y_j)$. The following table shows how to perform calculations.
583 \begin{table}[htbp]
584 \centering\begin{tabular}{c|l}
585 $f(x,y)$&\multicolumn{1}{c}{The commands from the package \texttt{calculator} for computing $f(\texttt{\symbol{92}nx},\texttt{\symbol{92}ny})$} \\ \hline
586 $\sin(y-x)$&\verb!\SUBTRACT{\ny}{\nx}{\sola}\SIN{\sola}{\solb}\slope=\solb pt!\\ \hline
587 \raisebox{-2ex}[0pt][0pt]{$2xy/(1+y^2)$}&\verb!\SUMfunction{\ONEfunction}{\SQUAREfunction}{\Fncty}!\\
588 &\verb!\Fncty{\ny}{\soly}{\Dsoly}\DIVIDE{\Dsoly}{\soly}{\tempa}!\\
589 &\verb!\MULTIPLY{\nx}{\tempa}{\tempb}\slope=\tempb pt!\\ \hline
590 \end{tabular}
591 \end{table}
592
593 From the old macros \verb!\avecfld! or \verb!\anothervecfld!, we will construct the new one \verb!\vecfldnew! by adding up to the former the two parameters as described above. According to
594 the description of new parameters and of known ones, the calling sequence of \verb!\vecfldnew! may have the form of
595 $$\textmtt{\symbol{92}vecfldnew\{\symbol{92}nx$=x_0+\Delta x$\}\{\symbol{92}ny$=y_0+\Delta y$\}\{$n_x$\}\{$n_y$\}\{$\ell$\}\{$f(\texttt{\symbol{92}nx},\texttt{\symbol{92}ny})$\}\{{\rm\TeX\ codes}\}\{$n_a$\}}$$
596 where $n_a$ is an estimate value for $M$ and can be adjusted to be greater or less than $M$. This flexible mechanism might be to increase or decrease the degree of
597 color shades. Finally, \verb!\intg! and \verb!\slope! should be reset to
598 zero at the end of each stage. Now, all materials to make the new macro are ready, and its definition is suggested to be
599 \bigskip\hrule
600 \noindent\begin{tabular}{@{}l}
601 \verb!\def\vecfldnew#1#2#3#4#5#6#7#8{%!\\
602 \verb!\newcount\intg \newdimen\slope \newdimen\interm \newdimen\fx \newdimen\fy!\\
603 \verb!\def\fintg{\interm=#8 \interm=\intg\interm%!\\
604 \verb! \ifdim\ifdim\slope<0pt -\fi\slope>\interm \advance\intg by 1\fintg\fi}!\\
605 \verb!\multido{#2}{#4}!\\
606 \verb!{\multido{#1}{#3}!\\
607 \verb!{\curvepnodes[algebraic,plotpoints=2]{0}{1}!\\
608 \verb!{\nx+((#5)*t)*(1/sqrt(1+(#6)^2))|\ny+((#5)*t)*(1/sqrt(1+(#6)^2))*(#6)}{P}!\\
609 \verb!#7\slope=10\slope \fintg \ifnum\intg>10\psline[linecolor=red]{->}(P0)(P1)!\\
610 \verb+\else\ifnum\intg=0\psline[linecolor=red!5]{->}(P0)(P1)+\\
611 \verb+\else\multiply\intg by 10\psline[linecolor=red!\the\intg]{->}(P0)(P1)\fi\fi+\\
612 \verb+\intg=0\slope=0pt+\\
613 \verb+}}}+
614 \end{tabular}\hrule\bigskip
615
616 If we predefine some scale of degrees, instead of the code $\verb!\ifnum\intg>10!\ldots\verb!\fi\fi!$, the structure \verb!\ifcase! can be used as
617 $$\begin{array}{c}
618 \verb!\ifcase\intg!\\
619 \verb+\psline[linecolor=red!5]{->}(P0)(P1)\or+\\
620 \verb+\psline[linecolor=red!10]{->}(P0)(P1)\or+\\
621 \vdots\\
622 \verb!\psline[linecolor=red]{->}(P0)(P1)\fi!
623 \end{array}$$
624
625 The first example is given with two values of $n_a$ to see how different the color shades are between the two cases. The left vector field in Figure \ref{Fig10}
626 is made of the calling sequence
627 \begin{verbatim}
628 \vecfldnew{\nx=-2.00+0.3}{\ny=-2.00+0.3}{14}{14}{0.3}{(\nx)-2*(\ny)}
629 {\fy=\ny pt \fx=\nx pt \advance\slope by -2\fy \advance\slope by \fx}{7pt}
630 \end{verbatim}
631 \begin{figure}[htbp]
632 \centering\includegraphics[width=4.6cm]{vecb5}
633 \hskip1cm\includegraphics[width=4.6cm]{vecb6}
634 \caption{The vector fields of the equation $y'=x-2y$ with $n_a=\texttt{7pt}$ (the left) and $n_a=\texttt{4pt}$ (the right)}\label{Fig10}
635 \end{figure}
636
637 In Figure \ref{Fig11}, the vector fields of the equations $y'=y-x$ and $y'=x(2-y)$ are respectively drawn by the calling sequences
638 \begin{verbatim}
639 \vecfldnew{\nx=-3.00+0.4}{\ny=-3.00+0.4}{15}{15}{0.35}{(\ny)-(\nx)}
640 {\fy=\ny pt \fx=\nx pt \advance\slope by -\fx \advance\slope by \fy}{5pt}
641 \end{verbatim}
642 and
643 \begin{verbatim}
644 \vecfldnew{\nx=-3.00+0.4}{\ny=-3.00+0.4}{15}{15}{0.35}{(\nx)*(2-(\ny))}
645 {\fy=\ny pt \fx=\nx pt \advance\slope by -\decimal\fx\fy
646 \advance\slope by 2\fx}{6pt}
647 \end{verbatim}
648 \begin{figure}[htbp]
649 \centering\includegraphics[width=6.2cm]{vecb3}
650 \hskip1cm\includegraphics[width=6.2cm]{vecb4}
651 \caption{The vector fields of the equation $y'=y-x$ (the left) and $y'=x(2-y)$ (the right).}\label{Fig11}
652 \end{figure}
653
654 Finally, we consider two more examples on vector fields of differential equations $y'=f(x,y)$ containing trigonometric or rational functions on their right side. The calling sequences
655 \begin{verbatim}
656 \vecfldnew{\nx=-3.00+0.4}{\ny=-3.00+0.4}{15}{15}{0.35}{sin(\nx)*cos(\ny)}
657 {\SIN{\nx}{\tmpa}\COS{\ny}{\tmpb}\MULTIPLY{\tmpa}{\tmpb}{\tmpc}
658 \slope=\tmpc pt}{0.6pt}
659 \end{verbatim}
660 and
661 \begin{verbatim}
662 \vecfldnew{\nx=-3.00+0.3}{\ny=-3.00+0.3}{20}{20}{0.3}{2*(\nx)*(\ny)/(1+(\ny)^2)}
663 {\SUMfunction{\ONEfunction}{\SQUAREfunction}{\Fncty}\Fncty{\ny}{\soly}{\Dsoly}
664 \DIVIDE{\Dsoly}{\soly}{\tempa}\MULTIPLY{\nx}{\tempa}{\tempb}
665 \slope=\tempb pt}{2.5pt}
666 \end{verbatim}
667 respectively result in the vector fields on the left and on the right in Figure \ref{Fig12}.
668
669 \begin{figure}[htbp]
670 \centering\includegraphics[width=6.2cm]{vecb1}
671 \hskip1cm\includegraphics[width=6.2cm]{vecb2}
672 \caption{The vector fields of the equation $y'=\sin(x)\cos(y)$ (the left) and $y'=2xy/(1+y^2)$ (the right).}\label{Fig12}
673 \end{figure}
674 \section{Drawing partitions of a simply connected plane domain}
675 \subsection{Description}
676 B\'{e}zier curves have been used in many different aspects, but mostly in computer graphics to model smooth curves designed by computer
677 programs. We just recall here the vector function of a B\'{e}zier curve of degree $n$ with $n+1$ control points whose position
678 vectors are $\mathbf{r}_0$, $\mathbf{r}_1$, \dots, $\mathbf{r}_n$. It is the vector function $\mathbf{r}(t)$ in a real variable $t\in[0,1]$ that
679 is defined as
680 \begin{equation}\label{eqn9}
681 \mathbf{r}(t)=\sum_{i=0}^n\binom{n}{i}t^i(1-t)^{n-i}\mathbf{r}_i.
682 \end{equation}
683 Since $\mathbf{r}(0)=\mathbf{r}_0$, $\mathbf{r}(1)=\mathbf{r}_n$ and $\mathbf{r}'(0)=n(\mathbf{r}_1-\mathbf{r}_0)$, $\mathbf{r}'(1)=n(\mathbf{r}_n-\mathbf{r}_{n-1})$,
684 we can take a curve such that it is closed and tangent to a line $(\Delta)$ at the point whose position vector is $\mathbf{r}_0$, by
685 letting $\mathbf{r}_n=\mathbf{r}_0$ and the points whose position vectors are $\mathbf{r}_0$, $\mathbf{r}_1$ and $\mathbf{r}_{n-1}$
686 all be on the line $(\Delta)$.
687
688 Taking a closed B\'{e}zier curve to be the boundary of a plane domain has the great advantage. That is because coordinates of points
689 on the curve are evaluated by polynomials, and the curve has necessary smoothness, beautiful enough for graphic illustrations.
690 \texttt{PSTricks} has the procedure \verb!\parametricplot! to draw such a curve. But, an important problem here is how to control
691 the coordinates of its points to construct a procedure for drawing a partition of a simply connected plane domain and coloring
692 (or marking) its cells having common points with the boundary of the domain. We particularly need such a procedure for illustrations
693 of essential notions in measure theory or double integral definition. Because of the limitation in accuracy imposed
694 by the \TeX\ arithmetic, we should mention about $2$-dimension vector functions of a B\'{e}zier curve of small degree (in fact, as small as possible).
695 According to the above requirements for the closed boundary of a simply connected domain, we will design a family of closed B\'{e}zier curves of
696 degree $6$, although we may extend their degree to $12$.
697
698 From the expression of $\mathbf{r}(t)$ in (\ref{eqn9}), we will construct the following functions and procedures:
699 \begin{itemize}
700 \item The factorial function \texttt{FACTORIAL}.
701 \item The binomial function \texttt{BINOMIAL}.
702 \item Polynomials $t^m(1-t)^n$.
703 \item A procedure to compute a sum of $7$ terms: values of $\mathbf{r}(t)$ as linear combinations
704 of the Bernstein polynomials
705 $$\binom{6}{k}t^k(1-t)^{6-k},\quad k=0,\ldots,6.$$
706 \end{itemize}
707 These functions and procedures are macros given by definitions with or without parameters. In the following subsections we will construct them step by step and
708 show how to make connections between them.
709 \subsubsection{Factorial functions and binomial coefficients}
710 To obtain the factorial function, a procedure for multiplying consecutively an integer $n$ with its diminished values will be constructed. For the declared
711 integer variables \verb!\Fa! and \verb!\Fct!, the latter will hold values of the function, and the former will hold factors that are multiplied consecutively
712 and reduced by $1$. Namely, if \verb!\Fa! is $0$ or $1$ then \verb!\Fct! takes $1$; else if $\texttt{\symbol{92}Fa}>1$ then \verb!\Fct! takes
713 the initial value of \verb!\Fa! to begin a loop: diminishing \verb!\Fa! by $1$ and updating \verb!\Fct! by multiplying its old value with the new value of \verb!\Fa!.
714 The loop is defined by the control sequence \verb!\Factor! and is ended when \verb!\Fa! is diminished to $1$; then, the factorial function obtains its value from
715 the one given back after calling \verb!\FACTORIAL! with one parameter.
716 \begin{verbatim}
717 \newcount\Fa\newcount\Fct
718 \newcount\tempA
719 \def\Factor{\ifnum\Fa=1\relax\else\advance\Fa by -1\multiply\Fct by \Fa\Factor\fi}
720 \def\FACTORIAL#1{\Fa=#1 \ifnum\Fa=0 \Fct=1\relax\else\Fct=\Fa \Factor\fi%
721 \global\tempA=\Fct}
722 \end{verbatim}
723 Since \TeX\ limits the largest integer number to $2^{30}-1$, we can evaluate only to
724 $$\textmtt{\symbol{92}FACTORIAL\{$12$\}}=12!=479001600.$$
725 Besides, the last value of \verb!\Fct!, which is right the one obtained from calling the function, is assigned to a global integer variable \verb!\tempA! for use
726 in other procedures. Finally, make the calling sequence
727 $$\textmtt{\symbol{92}FACTORIAL\{k\}\symbol{92}the\symbol{92}Fct}$$
728 to obtain and show up the value of $k!$. From these values we derive binomial coefficients by the formula
729 $$\binom{m}{n}=\frac{m!}{n!(m-n)!}.$$
730 A simple procedure that makes division of $m!$ by $n!$, then of the result by $(m-n)!$ can be performed by the control sequence
731 \verb!\BINOMIAL! with two parameters as follows
732 \begin{verbatim}
733 \newcount\BINOM
734 \newcount\temp\newcount\tmp
735 \def\BINOMIAL#1#2{%
736 \temp=#1\advance\temp by -#2
737 \FACTORIAL{#1}
738 \tmp=\tempA
739 \FACTORIAL{\temp}
740 \temp=\tempA
741 \divide\tmp by \temp
742 \FACTORIAL{#2}
743 \temp=\tempA
744 \divide\tmp by \temp\global\BINOM=\tmp}
745 \end{verbatim}
746 Again, the last value of \verb!\tmp! is assigned to a global integer variable \verb!\BINOM! for later use. Because the vector function of a B\'{e}zier
747 curve of degree $6$ is only needed, so are the binomial coefficients \verb!\BINOMIAL{!$6$\verb!}{!$k$\verb!}!, $k=0,1,\ldots,6$.
748 \subsubsection{Bernstein polynomials}
749 The construction of Bernstein functions is based on an iterative multiplication of the same value $t$ by a given number $m$ of times,
750 then the process is repeated with the value $1-t$ by a given number $n$ of times. The last result is multiplied by a variable that holds
751 the value of $\binom{m+n}{m}$. We will use an integer variable \verb!\kc! to count times of multiplication for the same factor $t$ or $1-t$.
752 The procedure of iterative multiplication \verb!\xmult! with one parameter $m$ or $n$ is a recursive one that is performed
753 iteratively until \verb!\kc! reaches the value $m$ or $n$.
754 \begin{verbatim}
755 \newdimen\Xa\newdimen\Yb\newcount\kc
756 \def\xmult#1{\ifnum\kc<#1\advance\kc by 1\Yb=\decimal\Xa\Yb\xmult{#1}
757 \else\relax\fi}
758 \end{verbatim}
759 Finally, the value of $t^m(1-t)^n$ that is hold by the variable \verb!\Yb! is multiplied by \verb!\BINOM!, the value $\binom{6}{m}$.
760 Thus, Bernstein polynomials are given by the following macro \verb!\BERNSTEIN! with three parameters that hold values of
761 $m$, $n$ and $t$, respectively.
762 \begin{verbatim}
763 \newdimen\BSTemp
764 \def\BERNSTEIN#1#2#3{\Xa=#3pt\kc=0\Yb=1pt\xmult{#1}\kc=0\Xa=-\Xa
765 \advance\Xa by 1pt\xmult{#2}\BINOMIAL{6}{#1}\global\BSTemp=\BINOM\Yb}
766 \end{verbatim}
767 Also, values of \verb!\BERNSTEIN! are assigned to a global variable.
768 \subsubsection{Vector functions of a plane B\'{e}zier curve of degree $6$}
769 We will construct here the vector function of a plane and closed B\'{e}zier curve with the control points
770 $M_0(x_0,y_0)$, $M_1(x_1,y_1)$, \dots, $M_6(x_6,y_6)$ that is chosen in such a way that the curve is tangent to
771 a line $(\Delta)$ at its initial point $M_0$. According to the mentioned properties of a B\'{e}zier curve, the requirements
772 for the curve are satisfied when $M_6=M_0$ and $M_0$, $M_1$, $M_5$ are all on the line $(\Delta)$.
773 \begin{figure}[htbp]
774 \centering\includegraphics[height=4.3cm]{Fig13}
775 \caption{A B\'{e}zier curve of degree $6$ with the required control points.}\label{Fig13}
776 \end{figure}
777 In case $n=6$, from (\ref{eqn9}) we derive the vector function $\mathbf{r}(t)$ with the two components
778 \begin{equation}\label{eqn10}
779 X(t)=\sum_{i=0}^6\binom{6}{i}t^i(1-t)^{6-i}x_i,\quad Y(t)=\sum_{i=0}^6\binom{6}{i}t^i(1-t)^{6-i}y_i.
780 \end{equation}
781 We first evaluate values of $X(t)$ by the procedures that just have been constructed, with a choice of $x_i$, $i=1,\ldots,6$, from a given $x_0$
782 and the requirements of the B\'{e}zier curve as in Figure \ref{Fig13}. For example, we may take
783 $$x_1=x_0-1.5,\quad x_2=x_0+2,\quad x_3=x_0+6,\quad x_4=x_0+5,\quad x_5=x_0+1.5,\quad x_6=x_0.$$
784 Moreover, we may change the shape of the curve by taking a factor $\alpha$ for $X(t)$. In short, we will make a procedure to evaluate the sum of terms
785 $\binom{6}{i}t^i(1-t)^{6-i}(\alpha x_i)$, $i=0,1,\ldots,6$. In fact, it is a procedure to add up values into a global variable \verb!\XBST! that is called
786 by a macro \verb!\XBC! with three declaring parameters for $x_i$, $t$ and $\alpha$. The value of $\alpha$ is used last when being multiplied by a
787 variable that holds $X(t)$. Such a procedure is suggested to be the following macro
788 \begin{verbatim}
789 \newdimen\Xrf\newdimen\Yrf
790 \newdimen\XBST\newdimen\YBST
791 \def\XBC#1#2#3{%
792 \BERNSTEIN{0}{6}{#2}
793 \Xrf=#1pt
794 \XBST=\decimal\BSTemp\Xrf
795 \BERNSTEIN{1}{5}{#2}
796 \Xrf=#1pt\advance\Xrf by -1.5pt
797 \advance\XBST by \decimal\BSTemp\Xrf
798 \BERNSTEIN{2}{4}{#2}
799 \Xrf=#1pt\advance\Xrf by 2pt
800 \advance\XBST by \decimal\BSTemp\Xrf
801 \BERNSTEIN{3}{3}{#2}
802 \Xrf=#1pt\advance\Xrf by 6pt
803 \advance\XBST by \decimal\BSTemp\Xrf
804 \BERNSTEIN{4}{2}{#2}
805 \Xrf=#1pt\advance\Xrf by 5pt
806 \advance\XBST by \decimal\BSTemp\Xrf
807 \BERNSTEIN{5}{1}{#2}
808 \Xrf=#1pt\advance\Xrf by 1.5pt
809 \advance\XBST by \decimal\BSTemp\Xrf
810 \BERNSTEIN{6}{0}{#2}
811 \Xrf=#1pt
812 \advance\XBST by \decimal\BSTemp\Xrf
813 \global\XBST=#3\XBST}
814 \end{verbatim}
815 In the macro, a control sequence of the form \verb!\decimal\Xdim! is for obtaining the decimal value of a variable \verb!\Xdim! without units
816 (\verb!pt!, by default). This can be defined by
817 \begin{verbatim}
818 \def\xch{\catcode`\p=12 \catcode`\t=12}\def\ych{\catcode`\p=11 \catcode`\t=11}
819 \xch \def\dec#1pt{#1}\ych \gdef\decimal#1{\expandafter\dec \the#1}
820 \end{verbatim}
821 Besides, the last line in the definition of \verb!\XBC! (\verb!\global\XBST=#3\XBST!) signifies \verb!\XBST! is adjusted for multiplication by
822 $\alpha$ when holding the current value of the sum $X(t)$. In Table \ref{bc-Table1}, some values
823 of \verb!\XBC! are compared with those of a simpler procedure in Maple\footnote{\footnotesize Maple
824 is a computer algebra system. It was first developed in 1980 by the Symbolic Computation Group at the University of
825 Waterloo in Waterloo, Ontario, Canada. Maple supports numeric and symbolic computations
826 and can be used as a programming language, which resembles Pascal.}.
827 \begin{table}[htbp]
828 \centering\begin{tabular}{|c|c|c|c|c|c|}\hline
829 &$(-2.4,0.23,1.5)$&$(4.2,0.45,1.1)$&$(-3.4,0.7,1.24)$&$(-0.89,0.4,1.5)$&$(5.21,0.5,2.15)$\\ \hline
830 \texttt{\symbol{92}XBC}&$\XBC{-2.4}{0.23}{1.5}\decimal\XBST$&$\XBC{4.2}{0.45}{1.1}\decimal\XBST$&$\XBC{-3.4}{0.7}{1.24}\decimal\XBST$&$\XBC{-0.89}{0.4}{1.5}\decimal\XBST$&$\XBC{5.21}{0.5}{2.15}\decimal\XBST$\\ \hline
831 Maple&$-2.41044$&$8.13235$&$-0.13696$&$2.78628$&$18.76008$\\ \hline
832 \end{tabular}
833 \caption{A comparison between some values of \textmtt{\symbol{92}XBC} and those of a procedure in Maple.}\label{bc-Table1}
834 \end{table}
835
836 Likewise, from a given $y_0$, we may have a choice of $y_i$, $i=1,\ldots,6$, as follows
837 $$y_1=y_0+2,\quad y_2=y_0+5,\quad y_3=y_0+3,\quad y_4=y_0-1,\quad y_5=y_0-2,\quad y_6=y_0.$$
838 The macro \verb!\YBC! is constructed in a quite analogous way as for \verb!\XBC! to evaluate values of $Y(t)$ in (\ref{eqn10}),
839 and the value $\beta Y(t)$ ($\beta$ is again an adjustment factor) is hold by a global variable \verb!\YBST!.
840
841 \subsubsection{Partition of a simply connected plane domain by a rectangular grid}
842
843 We consider here a simply connected plane domain $D$ surrounded by a B\'{e}zier curve of degree $6$ that will be depicted by
844 the procedure \verb!\NetDraw!. This is called together with its five parameters whose values are assigned to the five local variables
845 with their following meaning:
846 \begin{align*}
847 \texttt{\symbol{92}CellNum:}&\text{ The number of horizontal and vertical cells of the grid.}\\
848 \texttt{\symbol{92}Xref:}&\text{ The value of $x_0$.}\\
849 \texttt{\symbol{92}Yref:}&\text{ The value of $y_0$.}\\
850 \texttt{\symbol{92}Xfact:}&\text{ The value of $\alpha$.}\\
851 \texttt{\symbol{92}Yfact:}&\text{ The value of $\beta$.}
852 \end{align*}
853 We denote by $R$ a rectangular domain containing $D$ and having edges parallel to the coordinate axes.
854 A grid of rectangular cells will be depicted on $R$. According to the given values of $x_0$, $y_0$, $\alpha$ and $\beta$, the vertices of $R$
855 can be chosen as the points $(\verb!\XMin!,\verb!\YMax!)$, $(\verb!\XMax!,\verb!\YMax!)$, $(\verb!\XMax!,\verb!\YMin!)$, $(\verb!\XMin!,\verb!\YMin!)$, where
856 \begin{align*}
857 \textmtt{\symbol{92}XMin}&=\alpha(\textmtt{\symbol{92}Xref}-1.5),&&\textmtt{\symbol{92}XMax}=\alpha(\textmtt{\symbol{92}Xref}+6),\\
858 \textmtt{\symbol{92}YMin}&=\beta(\textmtt{\symbol{92}Yref}-2),&&\textmtt{\symbol{92}YMax}=\beta(\texttt{\symbol{92}Yref}+5).
859 \end{align*}
860 Then, the horizontal step size \verb!\Xsize! and the vertical step
861 size \verb!\Ysize! may be taken as
862 $$\mtt\\\texttt{Xsize}=\frac{\mtt\\\texttt{XMax}-\mtt\\\texttt{XMin}}{\mtt\\\texttt{CellNum}},\quad
863 \mtt\\\texttt{Ysize}=\frac{\mtt\\\texttt{YMax}-\mtt\\\texttt{YMin}}{\mtt\\\texttt{CellNum}}.$$
864
865 At first, the grid is made by using the structure \verb!\multido! to draw vertical and horizontal lines whose equations are
866 $$x=\texttt{\symbol{92}XMin}+i\texttt{\symbol{92}Xsize},\quad
867 y=\texttt{\symbol{92}YMin}+i\texttt{\symbol{92}Ysize},\quad i=0,\ldots,\texttt{\symbol{92}CellNum}.$$
868 Next, the B\'{e}zier curve is depicted by the command
869 $$\textmtt{\symbol{92}parametricplot[algebraic,fillstyle=solid]\{$0$\}\{$1$\}\{$\alpha X(t)$|$\beta Y(t)$\}}$$
870 and it is approximated by the sequence of points $(X_i,Y_i)$, $i=1,\ldots,N$, where $X_i$ and $Y_i$ are given from
871 the calling sequences
872 $$\textmtt{\symbol{92}XBC\{\symbol{92}XRef\}\{$t_i$\}\{\symbol{92}Xfact\}},\quad
873 \textmtt{\symbol{92}YBC\{\symbol{92}YRef\}\{$t_i$\}\{\symbol{92}Yfact\}}.$$
874
875 Finally, the most important algorithm is to determine cells that have points in common with the B\'{e}zier curve,
876 and to color them. The chosen ``filter'' method here can be described as follows: for each point $(X_i,Y_i)$ of the approximate sequence,
877 $i=1,\ldots, N$, we examine cells from left to right in horizontal direction, and from below to above in vertical direction. As soon as
878 being found, the cell containing $(X_i,Y_i)$ is specifically colored by the command \textmtt{\mtt\\pspolygon[fillstyle=solid,$\ldots$]} passing its four
879 vertices; then, we examine the next point $(X_{i+1},Y_{i+1})$, and so on. Actually, a structure of three nested \verb!\multido! loops
880 is used to perform this filter method, and the loop for counting points $(X_i,Y_i)$ is the most outer one. The algorithm to examine if
881 a cell contains $(X_i,Y_i)$ may have the form of
882 \begin{verbatim}
883 \ifdim\YBST<y\relax\else\advance y by \Ysize
884 \ifdim\YBST>y\relax\else
885 \ifdim\XBST<x\relax\else\advance x by \Xsize
886 \ifdim\XBST>x\relax\else
887 \pspolygon[fillstyle=solid,fillcolor=red]
888 (x,y)(x+\Xsize,y)(x+\Xsize,y+\Ysize)(x,y+\Ysize)(x,y)\relax
889 \fi\fi\fi\fi
890 \end{verbatim}
891 The single characters ``\verb!x!'', ``\verb!y!'' and the opertation ``\verb!+!'' will be replaced appropriately in the procedure \verb!\NetDraw! below.
892 For increasingly chosen values of $N$, we may know if the set of cells having points in common with the curve can cover the curve itself?
893 On the other hand, to increase the number of approximate points is corresponding to reduce the increment in the most outer loop \verb!\multido!.
894 For instance, if we take $N=100$, then the variable \verb!\nz! in the loop should be declared as $\texttt{\mtt\\nz}=0.00+0.01$ because
895 $t_i\in[0,1]$.
896
897 In summary, to illustrate a partition of a simply connected plane domain, we can apply the following procedure \verb!\NetDraw!. As mentioned above,
898 step by step, \verb!\NetDraw! can: draw the boundary of a plane domain $D$ by a B\'{e}zier curve of degree $6$, draw a partition of a rectangle $R$ containing $D$
899 by a grid of rectangular cells, and color cells having points in common with the boundary of $D$.
900 \bigskip
901 %\vskip2ex
902 \hrule
903 \begin{verbatim}
904 \def\NetDraw#1#2#3#4#5{%
905 \newcount\CellNum
906 \newdimen\XRef
907 \newdimen\YRef
908 \newdimen\Xfact
909 \newdimen\Yfact
910 \newdimen\XMin
911 \newdimen\XMax
912 \newdimen\YMin
913 \newdimen\YMax
914 \newdimen\Xsize
915 \newdimen\Ysize
916 \newdimen\tempx
917 \newdimen\tempy
918 \CellNum=#1
919 \XRef=#2pt
920 \YRef=#3pt
921 \Xfact=#4pt
922 \Yfact=#5pt
923 \XMin=\decimal\Xfact\XRef \advance\XMin by -1.50\Xfact
924 \XMax=\decimal\Xfact\XRef \advance\XMax by 6.00\Xfact
925 \YMin=\decimal\Yfact\YRef \advance\YMin by -2.00\Yfact
926 \YMax=\decimal\Yfact\YRef \advance\YMax by 5.00\Yfact
927 \Xsize=\XMax \advance\Xsize by -\XMin \divide\Xsize by \CellNum
928 \Ysize=\YMax \advance\Ysize by -\YMin \divide\Ysize by \CellNum
929 \parametricplot[algebraic,fillstyle=solid,fillcolor=yellow!80,plotpoints=200,
930 linewidth=0.5pt]{0}{1}{\XBsix{\decimal\XRef}{\decimal\Xfact}|
931 \YBsix{\decimal\YRef}{\decimal\Yfact}}
932 \multido{\nz=0.00+0.005}{200}{\XBC{\decimal\XRef}{\nz}{\decimal\Xfact}
933 \YBC{\decimal\YRef}{\nz}{\decimal\Yfact}
934 \multido{\nx=\decimal\XMin+\decimal\Xsize}{\the\CellNum}
935 {\tempx=\nx pt\multido{\ny=\decimal\YMin+\decimal\Ysize}{\the\CellNum}
936 {\tempy=\ny pt\ifdim\YBST<\tempy\relax\else\advance\tempy by \Ysize%
937 \ifdim\YBST>\tempy\relax\else
938 \ifdim\XBST<\tempx\relax\else\advance\tempx by \Xsize
939 \ifdim\XBST>\tempx\relax\else
940 \pspolygon[fillstyle=solid,fillcolor=blue!90,linecolor=black,
941 linewidth=0.2pt]
942 (\nx,\ny)(\decimal\tempx,\ny)(\decimal\tempx,\decimal\tempy)
943 (\nx,\decimal\tempy)(\nx,\ny)\relax\fi\fi\fi\fi}
944 }}
945 \advance\CellNum by 1
946 \multido{\nx=\decimal\XMin+\decimal\Xsize}{\the\CellNum}
947 {\psline[linewidth=0.2pt](\nx,\decimal\YMax)(\nx,\decimal\YMin)}
948 \multido{\ny=\decimal\YMin+\decimal\Ysize}{\the\CellNum}
949 {\psline[linewidth=0.2pt](\decimal\XMin,\ny)(\decimal\XMax,\ny)}
950 \parametricplot[algebraic,linecolor=white,plotpoints=200,linewidth=0.5pt]{0}{1}
951 {\XBsix{\decimal\XRef}{\decimal\Xfact}|\YBsix{\decimal\YRef}{\decimal\Yfact}}}
952 \end{verbatim}\hrule\bigskip
953
954 In the definition of \verb!\NetDraw!, the expressions $\alpha X(t)$, $\beta Y(t)$ are declared in the \verb!algebraic! form by the macros \verb!\XBsix!,
955 \verb!\YBsix! with two parameters that hold values of $x_0,\alpha$ and $y_0,\beta$, respectively. These macros are given by
956 the following definitions:
957 \begin{verbatim}
958 \def\XBsix#1#2{%
959 (1-t)^6*(#1)*(#2)+6*t*(1-t)^5*(#1-1.5)*(#2)+15*t^2*(1-t)^4*(#1+2)*(#2)+
960 20*t^3*(1-t)^3*(#1+6)*(#2)+15*t^4*(1-t)^2*(#1+5)*(#2)+
961 6*t^5*(1-t)*(#1+1.5)*(#2)+t^6*(#1)*(#2)}
962 \def\YBsix#1#2{%
963 (1-t)^6*(#1)*(#2)+6*t*(1-t)^5*(#1+2)*(#2)+15*t^2*(1-t)^4*(#1+5)*(#2)+
964 20*t^3*(1-t)^3*(#1+3)*(#2)+15*t^4*(1-t)^2*(#1-1)*(#2)+
965 6*t^5*(1-t)*(#1-2)*(#2)+t^6*(#1)*(#2)}
966 \end{verbatim}
967 \subsection{Examples}
968 Firstly, let us see the effect of change for the shape of a domain when adjusting its boundary by taking different values of $\alpha$ and $\beta$. The
969 calling sequence for this purpose may have the form of
970 \begin{align*}
971 &\textmtt{\mtt\\parametricplot[algebraic,plotpoints=200,linewidth=0.5pt]\{$0$\}\{$1$\}}\\
972 &\textmtt{\mtt\{XBsix\{$x_0$\}\{$\alpha$\}|\mtt\\YBsix\{$y_0$\}\{$\beta$\}\mtt\}}
973 \end{align*}
974 and its result is given in Figure \ref{Fig14}.
975 \begin{figure}[htbp]
976 \centering\includegraphics[height=3cm]{Fig14}
977 \caption{From left to right, corresponding to the couple of values:
978 $\alpha=2,\,\beta=2$; $\alpha=2.5,\,\beta=2$; $\alpha=2,\,\beta=2.5$.}\label{Fig14}
979 \end{figure}
980
981 The Table \ref{bc-table2} below provides three partitions of a domain $D$ with cells that decrease in size. In each case, \verb!\NetDraw! can
982 determine the cells that have points in common with the boundary curve and color them. The calling sequence here
983 takes a simple form
984 $$\textmtt{\mtt\\NetDraw\{$c$\}\{$x_0$\}\{$y_0$\}\{$\alpha$\}\{$\beta$\}}$$
985 The numerical argument $c$ is assigned to the local variable \verb!\CellNum!. The number of approximate points $(X_i,Y_i)$ for the boundary curve
986 is chosen to be $200$, by default, corresponding to the increment $\Delta\mtt{z}=0.005$. The number $N$ can be made larger and the filter procedure
987 for determining required cells may be more exact. In Table \ref{bc-table2}, the B\'{e}zier curves are depicted with the choice
988 $x_0=y_0=\alpha=\beta=2$.
989 \begin{table}[htbp]
990 \centering\begin{tabular}{cc}
991 \includegraphics[width=6cm]{b6of1}&\includegraphics[width=6cm]{b6of2}\\
992 \includegraphics[width=6cm]{b6of3}&\includegraphics[width=6cm]{b6of4}
993 \end{tabular}
994 \caption{The partitions of $D$ with $c=18$, $c=36$ and $c=63$.}\label{bc-table2}
995 \end{table}
996
997 \acknw
998 I am very grateful to
999 \begin{itemize}
1000 \item Timothy Van Zandt, Herbert Vo\ss, Dominique Rodriguez and Michael Sharpe for helping me with
1001 their great works on \texttt{PSTricks}.
1002 \item H\`an Th\hantt\rlap\accentcircflx\ Th\`anh for helping me with his pdf\hskip.03em\LaTeX\ program.
1003 \item Robert Fuster for his very useful package \texttt{calculator}.
1004 \end{itemize}
1005 \begin{thebibliography}{10}
1006 \bibitem{one} Dominique Rodriguez, Michael Sharpe \&\ Herbert Vo\ss. \textsl{\texttt{pstricks-add}: Additional Macros for PSTricks\/}.
1007 Version 3.60,
1008 \url{http://ctan.org/tex-archive/graphics/pstricks/contrib}, 2013
1009 \bibitem{two} Timothy Van Zandt, Michael Sharpe \&\ Herbert Vo\ss. \textsl{\texttt{pst-node}: Nodes and node connections}.
1010 Version 1.29,
1011 \url{http://ctan.org/tex-archive/graphics/pstricks/contrib}, 2013
1012 \bibitem{three} Helmut Kopka \&\ Patrick W. Daly. \textsl{Guide to \LaTeX \/}.
1013 Addison-Wesley, Fourth Edition, 2004, ISBN 0321173856
1014 \bibitem{four} Timothy Van Zandt. \textsl{User's Guide\/}. Version 1.5,\\
1015 \url{http://ctan.org/tex-archive/graphics/pstricks/base}, 2007
1016 \bibitem{five}Eitan M. Gurari. \textsl{Writing With \TeX \/}, McGraw-Hill, Inc., 1994, ISBN 0-07-025207-6
1017 \bibitem{six} Robert Fuster. \textsl{\texttt{calculator-calculus}: Scientific Calculations With \LaTeX \/}. Version 1.0a,
1018 \url{http://ctan.org/tex-archive/macros/latex/contrib/calculator}, 2012
1019 \end{thebibliography}
1020
1021 \end{document}
1022 \begin{thebibliography}{10}
1023 \bibitem{one} Dominique Rodriguez, Michael Sharpe \&\ Herbert Vo\ss. \textsl{\texttt{pstricks-add}: Additional Macros for PSTricks\/}.
1024 Version 3.60,
1025 \url{http://ctan.org/tex-archive/graphics/pstricks/contrib}, 2013
1026 \bibitem{two} Timothy Van Zandt, Michael Sharpe \&\ Herbert Vo\ss. \textsl{\texttt{pst-node}: Nodes and node connections}.
1027 Version 1.29,
1028 \url{http://ctan.org/tex-archive/graphics/pstricks/contrib}, 2013
1029 \bibitem{three} Helmut Kopka \&\ Patrick W. Daly. \textsl{Guide to \LaTeX \/}.
1030 Addison-Wesley, Fourth Edition, 2004, ISBN 0321173856
1031 \bibitem{four} Timothy Van Zandt. \textsl{User's Guide\/}. Version 1.5,\\
1032 \url{http://ctan.org/tex-archive/graphics/pstricks/base}, 2007
1033 \bibitem{five}Eitan M. Gurari. \textsl{Writing With \TeX \/}, McGraw-Hill, Inc., 1994, ISBN 0-07-025207-6
1034 \bibitem{six} Robert Fuster. \textsl{\texttt{calculator-calculus}: Scientific Calculations With \LaTeX \/}. Version 1.0a,
1035 \url{http://ctan.org/tex-archive/macros/latex/contrib/calculator}, 2012
1036 \end{thebibliography}