L A T EX Graphics with PSTricks This presentation is also - - PDF document

l
SMART_READER_LITE
LIVE PREVIEW

L A T EX Graphics with PSTricks This presentation is also - - PDF document

L A T EX Graphics with PSTricks This presentation is also available online. Please visit my home page and follow the links. http://www.math.msu.edu/ hensh 1. Resources (a) ImageMagick is a collection of (free) image manipulation tools. You


slide-1
SLIDE 1

L

A

T EX Graphics with PSTricks

This presentation is also available online. Please visit my home page and follow the links. http://www.math.msu.edu/∼hensh

  • 1. Resources

(a) ImageMagick is a collection of (free) image manipulation tools. You can find out more by visiting http://www.imagemagick.com (b) The L

A

T EX Graphics Companion.

  • Paperback: 608 pages
  • Publisher: Addison-Wesley Pub Co; 1st edition (April 15, 1997)
  • ISBN: 0201854694

(c) The L

A

T EX Graphics Companion (2nd Edition).

  • Paperback: 976 pages
  • Publisher: Addison-Wesley Professional; 2 edition (August 12, 2007)
  • ISBN: 0321508920

(d) PSTricks: Graphics and PostScript for T EX and L

A

T EX.

  • Paperback: 912 pages
  • Publisher: UIT Cambridge Ltd. (September 1, 2011)
  • ISBN: 1906860130

(e) The PSTricks web site. https://www.tug.org/PSTricks (f) PostScript(R) Language Tutorial and Cookbook (also called the “The Blue Book”)

  • Paperback: 256 pages
  • Publisher: Addison-Wesley Professional (January 1, 1985)
  • ISBN: 0201101793
  • 2. PSTricks

1

slide-2
SLIDE 2

(a) We start with some examples. −5 −4 −3 −2 −1 1 2 3 4 5 5 10 15 20 25 30 y = x2 Figure 1: Graphing simple functions. 1 2 3 4 5 6 −1 1 2 3 r = 1 + 2 sin θ r-θ Coordinate System Figure 2: Graphing with some fancy effects. 2

slide-3
SLIDE 3

−2 −1 1 2 1 2 3 r = 1 + 2 sin θ x-y Coordinate System Figure 3: Polar Graphs

b

1 P(2, 6) Figure 4: Area between two curves. 3

slide-4
SLIDE 4
  • u
  • v

Figure 5: A pair of vectors

  • u
  • v
  • v
  • u +

v

Figure 6: Vector addition with a grid. 4

slide-5
SLIDE 5

π 12 1

b b b

(a) (b) (c) Figure 7: Polar Grid x y z Figure 8: Sketching a cylinder. 5

slide-6
SLIDE 6

x y z

b b

Figure 9: Position Vectors Figure 10: Level Curves 6

slide-7
SLIDE 7

θ = α θ = β r = g1(θ) r = g2(θ) r = a Figure 11: Polar Area x y z

b

Figure 12: A Tangent Line 7

slide-8
SLIDE 8

−1 1 −1 1

c = 0.01 c = 0.025 c = 0.05 c = 0.075 c = 0.1 c = 0.11 c = 0.125

b

xy = c

P0

Figure 13: Lagrange Multipliers 8

slide-9
SLIDE 9

x y z Figure 14: Exposed Solid 9

slide-10
SLIDE 10

x y z Figure 15: Surface Integrals x y z Figure 16: Distorted Surface 10

slide-11
SLIDE 11

Figure 17: Fractals 11

slide-12
SLIDE 12

Isn’t PSTricks lots of fun

2013 !

Isn’t PSTric lots of

2013

Isn’t Tricks ts of fun

Figure 18: Lens Effects −1 1 2 3 −1 1 2 C Increasing Vector Magnitude Figure 19: Vector Field 12

slide-13
SLIDE 13
  • 3. PSTricks

To use PSTricks you must include the following lines in the preamble of your document.

1

\usepackage{pst-eucl}

2

\usepackage{calc}

3

\usepackage{pst-3dplot}%

4

\usepackage{pst-grad}

5

\usepackage{pst-plot,pst-math,pstricks-add}%

6

\usepackage{pst-all}

7

%\RequirePackage{pst-xkey} We should mention that there have been some incompatibilities between the pstcol package (used by PSTricks) and the graphics packages mentioned above. Using colors with PSTricks is similar to what has already been discussed. The real power of the PSTricks package is the ability to create graphics using L

AT

EX-like syntax.

13

slide-14
SLIDE 14

(a) Preliminaries PSTricks provides users with the capability to draw using the familiar syntax of L

AT

EX.

1

\psline[linecolor=blue,linewidth=1.25pt](-3,1)(2,2) The previous example might be easier to understand if we include more detail in the

  • sketch. Thus

1

\showgrid

2

\psline[linecolor=blue,linewidth=1.25pt,arrowscale=2]{->}(-3,1)(2,2)

1

\newpsobject{showgrid}{psgrid}{%

2

gridlabels=0pt%

3

,griddots=0%

4

,gridwidth=0.5pt%

5

,gridcolor=gray%

6

,subgriddiv=0%

7

,subgridwidth=0.25pt%

8

,subgridcolor=red}

14

slide-15
SLIDE 15

(b) Basic Graphics Objects Here’s a curve. Notice that the points used can be turned on (as shown) or off.

1

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)

2

\showgrid

3

\pscurve[linecolor=red,linewidth=1.5pt,showpoints=true]%

4

(\xmin,1)(0,2)(3,1)(\xmax,\ymax)

5

%\end{pspicture}

b b b b

where the values \xmin, \ymin,

  • etc. have been defined previously as

1

\def\xmin{-6}\def\xmax{6}

2

\def\ymin{-6}\def\ymax{6}

15

slide-16
SLIDE 16

We begin by setting the default unit(s) in PSTricks using the command \psset{unit=1cm} . This is actually the default value.

1

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)

2

\showgrid

3

\pscurve[linecolor=red,linewidth=1.5pt,showpoints=true]

4

(\xmin,1)(0,2)(3,1)(\xmax,\ymax)

5

\psbezier[style=myCurveStyle,linecolor=green]{-}%

6

(-4,1)(-2,3)(1,-4)(5,5)

7

%\end{pspicture}

b b b b

There are built-in shapes

1

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)

2

\showgrid

3

\psellipse[linecolor=blue,linewidth=1.5pt]

4

(1,0)(1,1.5)

5

\psdots[linecolor=red,linewidth=1.25pt](0,0)

6

\SpecialCoor

7

\uput{6pt}[180](0,0){$(0,0)$}

8

\NormalCoor

9

%\end{pspicture}

b

(0, 0)

16

slide-17
SLIDE 17

Here is a circle centered at (−2, −1) of radius 2.

1

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)

2

\showgrid

3

\pscircle[linecolor=red,linewidth=1.5pt]

4

(-2,-1){2}

5

%\end{pspicture} Here is the same object filled-in and clipped.

1

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)

2

\showgrid

3

\psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)}

4

\pscircle*[linecolor=red,linewidth=1.5pt]

5

(-2,-1){2}

6

\endpsclip

7

\pswedge*[linecolor=white](-2,-1){1}{15}{105}

8

%\end{pspicture}

17

slide-18
SLIDE 18

Finally, we plot some functions. To do this we’ll use some custom macros that give the user better control over the coordinate system.

1

\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)

2

\showgrid

3

\pstVerb{%

4

/f@ {dup mul} def % x^2

5

}

6

%%%%%%%%%%%%%%%%%%%%

7

%% Axes and Ticks %%

8

%%%%%%%%%%%%%%%%%%%%

9

\myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax)

10

\xTickMarks{\xmin}{\xmax}{1}

11

\yTickMarks{\ymin}{\ymax}{5}

12

%%%%%%%%%%%%%%%%%%%%%%%

13

%% Graphical Objects %%

14

%%%%%%%%%%%%%%%%%%%%%%%

15

\psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)}

16

\psplot[style=myPlotStyle]

17

{\xmin}{\xmax}{x f@}

18

\endpsclip

19

%%%%%%%%%%%%

20

%% Labels %%

21

%%%%%%%%%%%%

22

\SpecialCoor

23

\uput{6pt}[0](!3 dup f@){$y=x^2$}

24

\NormalCoor

25

\end{pspicture}

18

slide-19
SLIDE 19

−6 −5 −4 −3 −2 −1 0 1 2 3 4 5 6 −5 5 10 15 20 25 30 35 40

y = x2 And again, using better grid controls.

−6 −5 −4 −3 −2 −1 0 1 2 3 4 5 6 −5 5 10 15 20 25 30 35 40

y = x2

19

slide-20
SLIDE 20

Here’s something useful for integration theory. Use the sketch to estimate the integral below. 5

2

1 x dx y = 1 x

1 2 3 4 5 6 1 20

slide-21
SLIDE 21

Here is the code

1

\def\xmin{0}\def\xmax{6}

2

\def\ymin{0}\def\ymax{1}

3

\def\dommin{\xmin}\def\dommax{\xmax}

4

\VR{3in}{2.5in}

5 6

\newpsobject{newgrid}{psgrid}{%

7

gridlabels=0pt%

8

,griddots=0%

9

,gridwidth=0.5pt%

10

,gridcolor=gray%

11

,subgriddiv=4%

12

,subgridwidth=0.25pt%

13

,subgridcolor=red}

14

\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)

15

\newgrid

16

%%%%%%%%%%%%%%%%%%%%

17

%% Axes and Ticks %%

18

%%%%%%%%%%%%%%%%%%%%

19

\SpecialCoor

20

%% Labels go here

21

\rput[lr](!\xmax\space\xmax\space\xmin\space sub 15 div sub

22

\ymax\space\ymax\space\ymin\space sub 25 div sub){$y=\dfrac{1}{x}$}

23

\NormalCoor

24

\myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax)

25

%% Change these as needed. #1 - start, #2 - end, #3 - increment

26

\xTickMarks{\xmin}{\xmax}{1}

27

\yTickMarks{\ymin}{\ymax}{1}

28

\psclip{\psframe(\xmin,\ymin)(\xmax,\ymax)}

29

%% Graphing directives go here, e.g.,

30

\psplot[style=myPlotStyle]

31

{0.1}{\xmax}{1 x div}

32

\endpsclip

33

\SpecialCoor

34

\psline[fillstyle=crosshatch]{-}(3,0)(3.5,0)(!3.5 1 3

35

div)(!3 1 3 div)(3,0)

36

\psline[fillstyle=crosshatch]{-}(3.5,0)(4,0)(!4 1 3.5

37

div)(!3.5 1 3.5 div)(3.5,0)

38

\psline[fillstyle=crosshatch]{-}(4,0)(4.5,0)(!4.5 1 4

39

div)(!4 1 4 div)(4,0)

40

\psline[fillstyle=crosshatch]{-}(4.5,0)(5,0)(!5 1 4.5

41

div)(!4.5 1 4.5 div)(4.5,0)

42

\NormalCoor

43

\end{pspicture}

21

slide-22
SLIDE 22

(c) Plotting Data from a File Suppose that you wish to plot the following data. 0, 0.0628, 0.06279 0.1256, 0.12533 ... ... The following code does the trick.

1

%\begin{pspicture}(\xmin,\ymin)(\xmax,\ymax)

2

\showgrid

3

%% Axes and Ticks %%

4

\myaxes{<->}(0,0)(\xmin,\ymin)(\xmax,\ymax)

5

%% Graphical Objects %%

6

\psclip{\myframe(\xmin,\ymin)(\xmax,\ymax)}

7

\fileplot{plotData.txt}

8

\endpsclip

9

\SpecialCoor

10

\rput[lt](!\xmax\space\xmin\space sub 15 div

11

\ymax\space\ymax\space\ymin\space sub 25 div sub){$y=\sin x$}

12

\NormalCoor

13

%\end{pspicture} y = sin x

22

slide-23
SLIDE 23
  • 4. Several examples from geometry.

D C A B E 80◦ 30◦ A

80◦

B C

77◦ 40◦

D E

53◦ 50◦ 60◦

A B C P T V R E

23

slide-24
SLIDE 24
  • 5. A few exotic tricks.

(a) A vector field.

−2 −1 1 2 −2 −1 1 2 24

slide-25
SLIDE 25

(b) An ice-cream cone. x y z x y z x y z

25

slide-26
SLIDE 26

(c) A level surface. R S f(x, y, z) = c

b b

∆σk ∆Pk ∆Ak p p ∇f (xk, yk, zk) uk vk

26

slide-27
SLIDE 27

Figure 20: Fractals - Sierpinski Triangle x y z Figure 21: Sphere The equation of a sphere with radius r centered at the origin is x2 + y2 + z2 = r2 27

slide-28
SLIDE 28

80 160 −80 −160 20 · 103 40 · 103 60 · 103 80 · 103 100 · 103 x y Figure 22: Brownian Motion 1 2 3 4 −1 −2 1 2 3 4 −1 −2 −3 −4 −5 Figure 23: Not Sure What to Call This 28

slide-29
SLIDE 29

Figure 24: Tessellations?

slide-30
SLIDE 30

3 . 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 2 8 8 4 1 9 7 1 6 9 3 9 9 3 7 5 1 5 8 2 9 7 4 9 4 4 5 9 2 3 7 8 1 6 4 6 2 8 6 2 8 9 9 8 6 2 8 3 4 8 2 5 34 2 1 1 7 67 9 8 2 14 8 8 65 1 3 28 2 3 66 4 70 9 3 84 4 6 09 5 50 5 8 22 3 1 7 2 53 5 9 40 8 12 8 4 8 1 1 1 74 5 02 8 41 27 1 9 38 5 2 1 1 05 55 9 6 4 46 2 29 48 9 54 9 3 38 19 6 4 4 28 81 09 7 56 65 9 3 34 4 61 28 4 7 56 4 8 2 33 78 67 83 16 5 2 71 2 01 9 91 4 5 64 85 66 92 34 6 34 86 10 45 4 3 26 64 82 13 39 3 6 07 26 024 9 1 41 27 37 2 4 58 70 6 6 06 31 55 88 17 4 8 8 15 2 92 09 628 2 9 2 5 40 917 15 36 436 78 92 59 036 00 1 1 3 3 53 05 488 2 466 52 1 3 841 4 6 95 1 9 4 15 116 9 433 5 727 03 6 5 7 5 9 5 9 1 95 3 9 21 861 1 7 3 8 1 93 261 17 931 5 118 548 7 446 2 3 799 627 49 567 351 8 8 575 272 48 9 1 2 2 7 9 38 1 8 3 011 949 12 983 367 336 24 406 566 430 86 021 394 946 395 22 473 719 070 217 9 8 6 094 37 2 7 705 392 1 7 1 762 931 7 6 7 5 2 3 846 748 184 6 7 6 694 051 320 005 6 8 1 271 452 635 6 8 277 857 713 4 2 7 577 896 9 1 736 3 7 1 7872 146 844 090 122 495 343 0146 5 4 9 585 3 7 1 050 7 9 2 2 796 892 589 235 4201 995 611 212 9 2 1 960 864 0344 181 598 136 2977 4 7 7 130 9960 5 1 8 7072 1 1 3 499 9 9 9 9 837 297 8049 951 0597 317 3281 6 9 6 3 1 8595 2 4 4594 5 5 3 4 6 9 830 2 6 4 2 5 2 2 3 8 2 533 4 4 6 8 503 5 2 6 1 9 3 1 1 881 7101 000 3137 8 3 8 7528 8 6 5 8 7 5 3 3 2 8 381 4206 1 7 1 7 766 9147 3035 982 5349 4 2 8 755 4 6 8 7 3115 9562 863 882353787593751957781857780532171226806613001927876611195 Figure 25: π Spiral 30

slide-31
SLIDE 31

Transparency Effects

The sketch below shows the infinite plane x = 0. x y z x y z

x =

In a similar manner one can sketch the graphs of the equations y = 0 and z = 0. x y z x y z x = 0

y = 0

z = 0

Notice that these three planes break up three-space into eight octants. The first octant coincides with positive x, y and z-coordinates and is three-dimensional analogue of quadrant I in the plane. 31

slide-32
SLIDE 32

A Saddle Point

x y z x y z 32

slide-33
SLIDE 33

Example 1. A Familiar Curve Find the areas of the shaded regions. r1 = 2 cos θ − sin θ r2 = cos θ 1 2 −1 1

P

b

We first need to find the polar coordinates of point

  • f intersection, P. Setting r1 = r2 and solving we see

that θ = π/4. It follows that the area of green portion

  • f the shaded region is given by

AG = 1 2 π/4

  • r2

1 − r2 2

It follows that AG = 1 2 π/4 sin2 θ + 3 cos2 θ − 4 sin θ cos θ dθ = 1 2 π/4 1 + 2 cos2 θ − 2 sin 2θ dθ = 1 2 π/4 2 + cos 2θ − 2 sin 2θ dθ = 1 4(4θ + sin 2θ + 2 cos 2θ)

π/4

= 1 4{(π + 1 + 0) − (0 + 0 + 2)} = π − 1 4 Notice that AG + AB = 1 2 arctan 2 r2

1 dθ

(Compare this last equation to the gas tank problem.) Finally, can you find AY? 33

slide-34
SLIDE 34
  • Definition. The Gamma Function

Γ(x) = ∞ tx−1e−t dt (1) Here the (improper) integral converges absolutely for all x ∈ R except for the non-positive integers. In fact, the Gamma function can be extended throughout the complex plane (again, except for the non-positive integers). y = Γ(x)

b b b b b b

−4 −3 −2 −1 1 2 3 4 5 2 6 24 Observe that Γ(1) = ∞ t0e−t dt = −1 et

= 0 − (−1) = 1 and for positive integers n, integration by parts yields the recursive relation Γ(n + 1) = ∞ tne−t dt = −tne−t

+ n ∞ tn−1e−t dt = 0 + nΓ(n) and Euler had found his extension. That is, for each nonnegative integer n, he could now define the factorial by n! = Γ(n + 1) (2) 34

slide-35
SLIDE 35

Sketch the curve given by the equation below in polar coordinates. r1 = f(θ) = 2 cos θ − sin θ, 0 ≤ θ ≤ π (3) −2 −1 1 2 −1 1 m = tan(arctan 2) = 2 r1 = 2 cos θ − sin θ, 0 ≤ θ ≤ π

b

rθ-Coordinate System 1 2 3 4 5 6 −2 −1 1 2 r = f(θ) This busy sketch requires some explanation. Recall that the given (polar) equation defines a circle of radius √ 5/2 centered at (1, −1/2). The blue part of circle identifies that portion of polar equation r1 = 2 cos θ−sin θ, 0 ≤ θ ≤ arctan 2, i.e., when r1 ≥ 0. The red part identifies the part of the curve for arctan 2 ≤ θ ≤ π, i.e., when r1 < 0. The yellow portion is actually the sketch of the curve r2 = |f(θ)|, arctan 2 ≤ θ ≤ π (4) The vectors (arrows) trace out the curve r2 for 0 ≤ θ ≤ 2π. Notice that the equation in (4) yields two circles which are symmetric about the line y = 2x (shown in green). 35