[100] 002 Tutorial plot - msharpmath, The Simple is the Best

advertisement

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

[100] 002 revised on 2012.12.03

cemmath

The Simple is the Best

Chapter 2 Plot

2-1 What is the Concept of Umbrella

2-2 Multiple Curves and Built-In Geometries

2-3 Special Plots and Parameterized Curves in 2D

2-4 Treatment of Data

2-5 Manipulating Curves

2-6 Curves in 3D

2-7 Surfaces in 3D

2-8 Revolution in 3D

2-9 Popped and Filled Surfaces in 3D

2-10 Summary of Syntax

2-11 References

The introduction of Cemmath begins with explaining a new and amazing concept of Umbrella . In this chapter, we explain the elements and characteristics of Umbrella ‘ plot ’. Later, we will describe several different

Umbrellas such as ‘ int ’, ‘ ode ’, ‘ bvp ’, ‘ pde ’ etc.

Section 2-1 What is the Concept of Umbrella

Since the concept of Umbrella innovated in Cemmath is originated from an attempt to plot curves efficiently and in a systematic way, out first step is to analyze the plot process in the two-dimensional space.

β– 

Definition of Grid Span . Suppose that we need to draw a curve 𝑦 = π‘₯

2 over an interval of π‘Ž ≤ π‘₯ ≤ 𝑏 where π‘Ž = 0, 𝑏 = 3 . For the sake of brevity in explanation, let us take only 𝑛 = 4 nodes such that π‘₯ = [0,1,2,3] . This will be called the grid span which has four components

1

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

left-end, π‘Ž right-end, 𝑏 grid size, 𝑛 grid control, 𝑔

Thus a general definition of the grid span is

.x[n,g](a,b) where the leading dot, i.e. ‘.’, is intentional. The meanings of the left-end, the right-end as well as the grid size are straightforward. However, the grid control 𝑔 needs to be further discussed here. For a special case of 𝑔 = 1 , the nodes in the π‘₯ -coordinate are distributed linearly as π‘₯ 𝑖

= π‘Ž + (𝑏 − π‘Ž)

(𝑖 − 1) 𝑛 − 1

, 𝑖 = 1,2,3, … , 𝑛

In general, the grid control distributes the nodes such that 𝑑π‘₯ 𝑖

= 𝑔𝑑π‘₯ 𝑖−1

, 𝑑π‘₯ 𝑖

= π‘₯ 𝑖

− π‘₯ 𝑖

− 1

It is evident that the grid control 𝑔 represents a ratio between two successive spacings. Examples for a few grid controls are

.x[5,2] (0,15) makes x = [0,1,3,7,15] where dx = [1,2,4,8]

.x[5,0.5] (0,15) makes x = [0,8,12,14,15] where dx = [8,4,2,1]

.x[7,-2] (1,15) makes x = [1,2,4,8,12,14,15] where dx = [1,2,4,4,2,1]

.x[6,-0.5](1,14) makes x = [1,5,7,8,10,14] where dx = [4,2,1,2,4]

In other words, when the grid control takes a negative value, the grid spacing is symmetric. For practical use, default values, 𝑛 = 51 , 𝑔 = 1 , are used if not specified explicitly.

β– 

Elements of Umbrella . An Umbrella is normally composed of three parts: Hub , Stem and Spoke .

(1) The Hub begins with a dot ‘.’ and describes a grid span. The identifier after

2

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

‘.’ does not represent a member function of a class in C++, but designates an independent variable used in the forthcoming mathematical expression within the Stem. The Hub defined as

.x[n,g](a,b) is indeed the same as the grid span mentioned above.

(2) The Stem is enclosed by ‘( )’ and contains mathematical functions of interest.

The variable defined in the Hub is regarded as the independent variable in the

Stem. Other pre-defined variables are used as if they were local variables. For example, when one writes

#> a = 2; plot .x[21,1](-2,2) ( x*x-a ); the variable ‘a’ can participate in the definition of the Stem without any further declaration, while the Hub variable ‘x’ is internal to the Umbrella. In addition, the following Cemmath command

#> a = 2; x = 3; plot .x[21,1](-2,2) ( x*x-a ); y = x+4; yields y = 7 . The internal variable x for the Umbrella ‘ plot ’ has nothing to do with the external variable x outside of the Umbrella even if their names are the same.

(3) The Spoke begins with a dot ‘.’ and manipulates additional operations on the figure. It is apt to consider the Spoke as something similar to the member function of a class in C++. This is true in one sense, but is not in another sense.

The behaviors of the Spoke and the member function of C++ are notably different.

In order to understand the roles of the above three elements, let us start with a simple Cemmath command

#> plot // name of Umbrella

.x[21,1](-2, 2) // Hub

( x*x ) // Stem

.flip ; // Spoke

3

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

which is the same as

#> plot .x[21,1](-2,2) ( x*x ) .flip ; since the style of C-language is adopted in Cemmath. Figure 1 is the result shown in the screen. Note that the bare curve without any decoration is plotted.

Now, let us discuss what kinds of processes have been performed internally. First, Hub (i.e. the grid span as was mentioned earlier) prepares 21 node points over an interval of −2 ≤ π‘₯ ≤ 2 with a uniform spacing ( 𝑔 = 1 ).

Next, Stem evaluates 𝑦 = π‘₯

2

at all the corresponding points. Then, Spoke

‘ flip ’ transforms the so-obtained data in a manner (𝑋, π‘Œ) = (π‘₯, 𝑦) which represents a symmetry with respect to a line 𝑦 = π‘₯ . This is our first success to plot a curve with the aid of Umbrella ‘ plot ’. The power of Spokes inherits from a variety of useful operations.

In most software, plot command (or similar ones) performs a single mission of plotting figures. On the contrary, Umbrella ‘ plot ’ in Cemmath utilizes a series of Spokes to fulfill user’s diverse purposes.

Figure 1 Graph of x

ο€½ y 2 by use of Umbrella ‘ plot ’

β–  Spokes for 2D curves . In the following, summarized are some of the

Spokes applicable for 2D curves. Note that (x,y) denotes the data point in the last Spoke, and (X,Y) the data point in the current Spoke. Many of the Spokes listed below can be applied for 3D curves and 3D surfaces, too.

4

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

plot.now

; plot; // plot immediately plot+.hold

; hold the current plot for overwriting

plot .hold

; plot new and hold

.

flip (X,Y) = (y,x) symmetry about line y = x

.

xmove (a) (X,Y) = (x+a,y) translate in x-direction by a

.

ymove (b) (X,Y) = (x,y+b) translate in y-direction by b

.

move (a,b) (X,Y) = (x+a,y+b) translate by a vector (a,b)

.

xscale (sx,a=0) (X,Y) = (a+sx*(x-a),y) elongate in x-dir about line x=a

.

yscale (sy,b=0) (X,Y) = (x,b+sy*(y-b)) elongate in y-dir about line y=b

.

xlog (X,Y) = (log10(x), y)

.

ylog (X,Y) = (x, log10(y))

.

xylog / loglog (X,Y) = (log10(x), log10(y))

.

xsym (a=0) (X,Y) = (2*a-x, y) symmetry about line x=a

.

ysym (b=0) (X,Y) = (x, 2*b-y) symmetry about line y=b

.

osym @(xo,yo) (X,Y) = (2*xo-x, 2*yo-y) symmetry about point (xo,yo)

.

scale (sx,sy) @(xo,yo) (X,Y) = (xo+sx*(x-xo),yo+sy*(y-yo))

.

zrot (t) @(xo,yo) rotate counterclockwise about (xo,yo)

.

lsym (a,b,c) symmetry with respect to line ax+by+c = 0

.

lstep lower-step function

.

ustep upper-step function

.

xstem stem with respect to the x-coordinate

.

ystem stem with respect to the y-coordinate

.

xystem stem with respect to the x- and y-coordinates

.

stem stem with circle

.

link connect piecewise curve to the last curve

.

merge make all curves to be a single curve

.

movelink connect piecewise curves to the last ending point

.

copy [n] (dx,dy) duplicate a total of n curves and move by (dx,dy)

.

copylink [n] (dx,dy) copy[n](dx,dy) and make all curves to be a single curve

.

xmean (xm) extracts a mean value of x

.

ymean (ym) extracts a mean value of y

.

togo (A) extracts matrix A for vertex data of each curve

.

allout (A) extracts matrix A for all the vertex data

.

info print out information on curves and vertex and a few more will be discussed later

Of course, all the Spokes attached to Stem are processed in order of appearance.

5

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Nevertheless, it is worthy of emphasis that some Spokes are not commutative.

For example ‘.

xsym.flip

’ is not the same as ‘.

flip.xsym

’. Figure 2 shows a few examples of using Spokes by the following commands.

#> plot .x[21](0,5) ( exp(x/2) ) ;

#> plot .x[21](0,5) ( exp(x/2) ) .ustep ;

#> plot .x[21](0,5) ( exp(x/2) ) .ystem ;

#> plot .x[21](0,5) ( exp(x/2) ) .xstem ;

#> plot .x[21](0,5) ( exp(x/2) ) .xystem ;

Figure 2 Examples of various Spokes for Umbrella ‘ plot ’

It is also possible to plot Figure 2 by using pre-defined matrices

#> X = (0,5).span(21);

#> F = exp(X/2);

#> plot(X,F) ;

#> plot(X,F) .ustep ;

#> plot(X,F) .ystem ;

#> plot(X,F) .xstem ;

#> plot(X,F) .xystem ;

β– 

Nature of Spoke . The Spoke has a nature analogous to the member functions of a class in C++, and can be omitted if not necessary. However, there

6

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

exist several notable differences between the Spoke and the member function.

First, Spoke can treat various types of arguments. Second, the internal variable defined in Hub (e.g. ‘x’) can be explicitly used in some Spokes. Third,

Spoke can handle vector operators (dot product and cross product). These will be discussed in detail later.

Section 2-2 Multiple Curves and Built-In Geometries

β– 

Multiple Curves . When multiple curves over the same grid spacing need to be plotted, Stem can include multiple expressions. In Cemmath, it is very clear to understand overwriting of curves. As an analogy to ++ operator in

C-language, ‘ plot+ ’ is innovated to fulfill this purpose.

The following example illustrates the case of both multiple curves and overwriting. It is clear that Figure 3 shows the desired performance of Spokes

‘ lstep ’ (lower step) and ‘ ustep ’ (upper step).

#> plot .x[21](0,2*pi) ( sin(x),cos(x) ); // Figure 3

#> plot+.x[21](0,2*pi) ( sin(x),cos(x) ).ustep; // upper step

#> plot+.x[21](0,2*pi) ( sin(x),cos(x) ).lstep; // lower step

Figure 3 Examples of ustep and lstep

When the current curve is used to generate multiple curves by duplication,

Spokes ‘ copy ’ and ‘ copylink ’ are very useful. Periodic functions can be very easily drawn by using these Spokes. A difference between ‘ copy ’ and ‘ copylink ’ is that ‘ copy ’ generates curves separately, while ‘ copylink ’ connects all the

7

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

curves.

#> plot.x[11](0,pi) (sin(x)).copy [5](pi/2,0.5); // Figure 4

#> plot.x[11](0,pi) (sin(x)).copylink[5](pi/2,0.5); // Figure 5

The above commands clearly explain the difference between ‘ copy ’ and

‘ copylink ’, as shown in Figures 4 and 5. The total number of curves duplicated by ‘ copy ’ and ‘ copylink ’ are designated by ‘[ ]’ which resembles the definition of array.

Figure 4 Example of copy Figure 5 Example of copylink

β– 

Built-In Geometries . Geometries most frequently encountered in 2D would be point, line, circle, square, rectangle, trapezoid, triangle, etc. In this regard, Cemmath supports built-in geometries replacing Stem by well-known names. An aftermath of omitting Stem is the ambiguity associated with preparing nodes. This problem can be resolved by introducing a pair of brackets

‘[ ]’ inside which grid span can be implemented, whenever necessary. Listed below are a few numbers of built-in geometries.

.

triangle (a,b,c )

8

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

.

square (a )

.

star (r )

.

rectangle (a,b )

.

parallel (a,b, theta )

.

trapezoid (a,b, height)

.

circle [nt=51,gt=1] (radius)

.

polygon [nvert,gt=1] (radius) // nvert >= 3

.

ellipse [nt=51,gt=1] (a,b )

.

point (xo,yo)

.

vector [scale=1,headscale=1,headangle=30] (a,b)

.

line (x1,y1, x2,y2)

Figure 6 shows the results of

#> plot .circle(1); // .circle [nt=51,gt=1] (radius)

#> plot+.ellipse(2,0.5); // .ellipse [nt=51,gt=1] (a,b )

#> plot+.polygon[3](1); // .polygon [nvert,gt=1] (radius)

#> plot+.triangle(2,2,2); // .triangle (a,b,c )

#> plot+.square(2); // .square (a )

There is a slight difference between triangle and polygon[3]. Spoke ‘ polygon ’ always centers geometries at the origin, and needs input as a radius. But Spoke

‘ triangle ’ has the origin as a starting point, and the side length is given as input.

Figure 6 Built-in geometries in 2D

9

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Further shown in Figure 7 are the results of

#> plot .star(0.1); // .star (radius)

#> plot+.rectangle(2,3); // .rectangle(a,b)

#> plot+.parallel(4,3, pi/3); // .parallel (a,b, theta)

#> plot+.trapezoid(3,2, 2); // .trapezoid(a,b, height)

Figure 7 Built-in geometries in 2D

Section 2-3 Special Plots and Parameterized Curves in

2D

β–  Vector Plot . The built-in geometry ‘ vector ’ can be utilized to illustrate several important features of phenomena. The definition of Spoke

‘ vector ’ was

.vector [scale=1, headscale=1, headangle=30] (a,b)

The element scale is used to control the vector length, while the headscale controls the appearance of arrowhead. The default size of arrowhead (i.e. headscale

= 1 ) is 1/20 of the vector length. If headscale

= 0 , an arrowhead will not be shown. Furthermore, a negative value of scale corresponds to a constant length of vectors with an arrowhead of constant size (-scale/20*headscale) .

10

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Users should not be confused with Spoke ‘ line ’ and ‘ vector ’. Spoke ‘ line ’ connects two points listed as arguments, whereas Spoke ‘ vector ’ depicts a direction vector located at a given origin. As a matter of fact, the following two commands are the same plot .line(a,b, c,d) and plot .vector[1,0](c-a,d-b) .move(a,b)

A practically important example would be tangential velocity vectors along a circle. It is not difficult to understand that the result of the following corresponds to Figure 8.

#> .hold; // create a new plot window and hold on for overwriting

plot.circle(1);

for.n(0,19) {

t = n*pi/10;;

x = cos(t);; y = sin(t);;

plot.star(0.04) .move(x,y);

plot.vector(-y,x) .move(x,y);

}

#> plot;

Figure 8 Tangential velocities along a circle

The phase diagram in Figure 9 arises from a differential equation for a pendulum 𝑦′′ + sin 𝑦 = 0 from which 𝑦

1

= 𝑦

2

, 𝑦

2

= − sin 𝑦

1

are defined.

The corresponding Cemmath commands are

#> .hold;

for.y1(-5,5.01, 0.5) // for(y1 = -5; y1 < 5.01; y1 += 0.5)

11

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

for.y2(-3,3.01, 0.5) { // for(y2 = -3; y2 < 3.01; y2 += 0.5)

plot.vector[0.3,3] (y2,-sin(y1)) .move(y1,y2); // Figure 9a

}

plot;

#> .hold;

for.y1(-5,5.01, 0.5)

for.y2(-3,3.01, 0.5) {

plot.vector[-0.1,3] (y2,-sin(y1)) .move(y1,y2); // Figure 9b

}

plot;

This special plot will be treated later again.

Figure 9 Phase diagram for a pendulum motion

β– 

Parameterized Curve . One unique case of parameterized curves in plane is the polar curve defined as π‘₯ = π‘Ÿ cos πœƒ, 𝑦 = π‘Ÿ sin πœƒ and is implemented in Cemmath with a syntax plot .t[n=51,g=1](a,b) ( <<opt>>, r(t), ... ) .cyl // 2D curve(s)

In other words, Spoke ‘ cyl ’ (or ‘ polar ’) converts the curves from rectangular to polar coordinates. In general, the parameterized curves in plane have a form of π‘₯ = π‘₯(𝑒), 𝑦 = 𝑦(𝑒)

12

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

where π‘Ž ≤ π‘₯ ≤ 𝑏 . To designate a certain variable to be a parameter, the character ‘ @ ’ is used for convenience. In this regard, the following Cemmath syntax plot .@u[n=51,g=1](a,b) ( <<opt>>, x(u), y(u) ) // only one curve plot .@u[n=51,g=1](a,b) ( <<opt>>, r(u), t(u) ).cyl // 2D curve draws a parameterized curve as desired, where the character ‘ @ ’ is employed to represent parameter . If the character ‘ @ ’ is omitted, two curves will appear with 𝑒 as the horizontal axis.

Some of the curves drawn in Figures 10-12 bear artistic nature, and interested readers are recommended to refer literature cited herein.

#> plot.t[101](0,2*pi) ( cos(t), cos(2*t) ).cyl; // x*x + y*y - x = 0

Figure 10 Polar plot

13

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

#> (a,b) = (12,5);; // Epicycloid

#> plot .@t[1001](0,10*pi) (

<< u = (a/b+1)*t >>,

(a+b)*cos(t)-b*cos(u), (a+b)*sin(t)-b*sin(u)

);

Figure 11 An epicycloid

#> (a,b) = (501,7);

#> (a,b) = (501,7);

(rx,ry) = (10,10);

(bx,by) = (1,2);

(cx,cy) = (9,2);

(ex,ey) = (6.5,5.5); // Rose and butterfly

14

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

#> .hold;

#> plot.t[3001](0,2*pi*a) ( 5*sin(b*t) ).cyl.move(rx,ry); // A rose is a rose ....

#> plot.t[1001](0,10*pi) ( exp(cos(t))-2*cos(4*t)+(sin(t/12))^5 ).cyl

.zrot(pi/6).move(bx,by); // butterfly

#> plot.ellipse(12,8).zrot(50*pi/180).move(ex,ey); // inclined ellipse

#> plot.circle(2) .move(cx,cy); // necklace of radius 2

#> for(t = 0; t <= 2; t += 0.1) plot.circle[11](0.2) .move(cx+2*cos(pi*t), cy+2*sin(pi*t) );

#> plot;

// P.M. Maurer, A rose is a rose ..., Math. Monthly, 94 (1987), pp. 631-645.

// T.H. Fay, A study in step size, April issue, Mathematics Magazine (1997).

Figure 12 Butterfly, rose and necklace within an inclined ellipse

β–  Phase Diagram . The phase diagram shown in Figure 9 involved a differential equation written as 𝑦′′ + sin 𝑦 = 0 with 𝑦

1

= 𝑦

2

, 𝑦

2

= − sin 𝑦

1

.

This can be implemented in a much easier way by introducing Spoke ‘ phase ’ the syntax of which is plot .u[n=21,g=1](a,b)

.v[n=21,g=1](c(u),d(u)) ( u ' , v ' )

.phase[scale=1,headscale=1,headangle=30]

The result shown in Figure 9 is considered again in Figure 13 by the following commands for two different boundaries

#> plot.y1[15](-5,5).y2[15](-3,3) ( y2,-sin(y1) ).phase[0.3,3];

#> plot.y1[15](-5,5).y2[15](-3*cos(pi/11*y1),3*cos(pi/11*y1))

( y2,-sin(y1) ).phase[0.3,3];

15

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 13 Phase diagram for a pendulum motion with Spoke ‘ phase ’

Section 2-4 Treatment of Data

The most powerful aspect of Spoke ‘ togo ’ is that vertex data can be withdrawn at any stage of Spoke. For example, the following commands

#> plot.x[11](-1,1) (1-x*x) .togo(P) // plot a parabola, and get data

.zrot(pi/6) .togo (Q) // rotation about z-axis, and get data

.lsym(3,2,1) .togo(R); // line symmetry about 3x+2y+1 = 0, and get data

#> P; Q; R; // print data points after each Spoke extract vertex data in 11 2 matrix form after each Spoke

P =

[ -1 0 ]

[ -0.8 0.36 ]

[ ... ... ]

[ 0.8 0.36 ]

[ 1 0 ]

16

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Q =

[ -0.86603 -0.5 ]

[ -0.87282 -0.088231 ]

[ ... ... ]

[ 0.51282 0.71177 ]

[ 0.86603 0.5 ]

R =

[ 0.33309 0.29941 ]

[ -0.044394 0.46405 ]

[ ... ... ]

[ -1.3158 -0.50731 ]

[ -1.2562 -0.91479 ]

These vertex data at each Spoke can be handled by users for other purposes, e.g. saving to the file.

In some cases, all the vertex data in one layout need to be withdrawn. This can be accomplished by Spoke ‘ allout ’. The following commands

#> plot .square(1) .togo(P);

#> plot+ .polygon[3] .togo(Q).allout(R).info; // togo and allout

#> P; Q; R; illustrate the difference between ‘ togo ’ and ‘ allout ’ as follows.

P =

[ 0 0 ]

[ 1 0 ]

[ 1 1 ]

[ 0 1 ]

[ 0 0 ]

Q =

[ 0 1 ]

[ -0.86603 -0.5 ]

[ 0.86603 -0.5 ]

[ 0 1 ]

R =

[ 0 0 ]

[ 1 0 ]

[ 1 1 ]

17

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

[ 0 1 ]

[ 0 0 ]

[ 0 1 ]

[ -0.86603 -0.5 ]

[ 0.86603 -0.5 ]

[ 0 1 ]

In addition, Spoke ‘ info ’ displays the number of disconnected curves and the vertex data in each curve, as well as the total number of vertices, as follows

//==========================================

// # of curves = 2

// # of vertex = 9

// # of points in each curve

// 5 4

//==========================================

Section 2-5 Manipulating Curves

β–  Curve Identification . Representing a curve by a finite number of points may entail the following definition of curves. A curve 𝐢 𝑖

is defined as

𝐢 𝑖

= {(π‘₯ 𝑗

, 𝑦 𝑗

)| 𝑗 = 1,2,3, … , 𝑛 𝑖

} and the point at 𝑗 = 1 is denoted by 𝐢 𝑖𝑠

(starting point), and the point at 𝑗 = 𝑛 𝑖

is denoted by 𝐢 𝑖𝑠

(ending point). All other points then lie in between in view of connectivity (not by spatial location).

Connecting two curves 𝐢

1

and 𝐢

2

into one curve 𝐢

3

can be considered as creating a new curve with a new ending point 𝐢

3𝑒

= 𝐢

2𝑒

. The original ending point 𝐢

1𝑠 inner points in 𝐢

in curve 𝐢

3

1

and the starting point 𝐢

2𝑠 in 𝐢

2 are treated as

after connection. This concept will be helpful in working with many composite curves generated from different mathematical functions.

β–  Geometric Centers . Geometric centers of a curve are defined as

18

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

π‘₯ π‘š

= 𝑛

1 𝑛

∑ π‘₯ 𝑖 𝑖=1

, 𝑦 π‘š

= 𝑛

1 𝑛

∑ 𝑦 𝑖 𝑖=1

However, for a closed curve with 𝐢 𝑖𝑠 π‘₯ π‘š

= 𝑛−1

1 𝑛 − 1

∑ π‘₯ 𝑖 𝑖=1

,

= 𝐢 𝑖𝑒

, geometric centers are defined as 𝑦 π‘š

= 𝑛−1

1 𝑛 − 1

∑ 𝑦 𝑖 𝑖=1 since the starting and the ending points are identical. In some cases, it is necessary to place curves at its geometric centers, e.g. the results obtained by

#> .hold;

plot .t[51](0,2*pi) ( 1+cos(t) ).cyl;

plot .star(0.1);

for.n(0, 50) {

t = n*2*pi/50;;

r = 1+cos(t);;

plot .polygon[3](0.02).move( r*cos(t),r*sin(t) );

}

plot .t(0,2*pi) ( 1+cos(t) ).cyl

.xmean(xm).ymean(ym).move(-xm,-ym).xmean(xm2);

#> plot;

#> xm; ym; xm2; xm = 0.500000 ym = 0.000000 xm2 = 0.000000 are shown in Figure 14. Note that Spoke ‘ xmean ’ and ‘ ymean ’ are evaluated at the time of appearance.

19

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 14 Geometric centers

β–  Disconnections . Frequently, disconnections may exist in the curve.

These disconnections can be removed by using Spoke ‘ link ’ and ‘ merge ’. For example, Figure 15 shows two cases of using ‘ link ’ and ‘ merge ’. By the use of

Spoke ‘ link ’, a single disconnection at π‘₯ = 2 has been removed as can be seen.

The Spoke ‘ merge ’ makes a single curve by connecting all the curves.

#> .hold;

plot .x[2](0,1) (x);

plot .x[2](1,2) (x-1);

plot .x[2](2,3) (x-2).link; // Figure 15a plot;

#> .hold;

plot .x[2](0,1) (x);

plot .x[2](1,2) (x-1);

plot .x[2](2,3) (x-2).merge; // Figure 15b plot;

Figure 15 Removing disconnection with link and merge

20

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

When the Spoke ‘ link ’ is applied, the subsequent Spoke such as ‘ zrot ’ then affects the previously defined curve. We can see this behavior by Cemmath command

#> .hold;

plot .x[11](0,2) (4-x*x);

plot .x(2,4) ( 0.3*x ).zrot(pi/6); // Figure 16a plot;

#> .hold;

plot .x[11](0,2) (4-x*x);

plot .x(2,4) ( 0.3*x ).link.zrot(pi/6); // Figure 16b plot; and by the result shown in Figure 16.

Figure 16 The effect of link

A special care should be taken in using Spoke ‘ link ’ and ‘ merge ’.

Whenever the ending point 𝐢 𝑖𝑒

coincides with the starting point 𝐢 𝑗𝑠

of the next curve, the starting point 𝐢 𝑗𝑠

is eliminated and thus the number of points is reduced by one. This is natural as we expect it should be.

In a variety of situations, it is desired to connect many segments one-byone by placing the ending point 𝐢 𝑖𝑒

at the starting point 𝐢 𝑗𝑠

. In doing this, we wish not to worry about creating each segment at the desired location. What we want is to make many curves wherever one feels comfortable (much like curve-

21

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

making factory) and move them to desired points. This convenient operation can be fulfilled by using Spoke ‘ movelink ’. Figure 17 illustrates the use of

Spoke ‘ movelink ’ to make a circle with a series of tangent vectors where the corresponding Cemmath commands are

#> .hold;

t = pi/10;;

plot .point(-0.5,0);

for.n(0,19) plot .vector[1,0](cos(n*t),sin(n*t)) .movelink;

#> plot;

Note that a use of Spoke ‘ point ’ just controls a starting point. Without this command, the curve will be shifted by 0.5.

Figure 17 Manipulating segments by movelink

Section 2-6 Curves in 3D

β–  Parameterization of 3D curve . The curves in three-dimensional space are typically parameterized in the rectangular, cylindrical and spherical coordinates as

𝐢 = {(π‘₯, 𝑦, 𝑧)|π‘Ž ≤ 𝑒 ≤ 𝑏,

𝐢 = {(π‘Ÿ, πœƒ, 𝑧)|π‘Ž ≤ 𝑒 ≤ 𝑏,

𝐢 = {(π‘Ÿ, πœ‘, πœƒ)|π‘Ž ≤ 𝑒 ≤ 𝑏, where π‘₯ = π‘₯(𝑒), 𝑦 = 𝑦(𝑒), 𝑧 = 𝑧(𝑒)} π‘Ÿ = π‘Ÿ(𝑒), πœƒ = πœƒ(𝑒), 𝑧 = 𝑧(𝑒)} π‘Ÿ = π‘Ÿ(𝑒), πœ‘ = πœ‘(𝑒), πœƒ = πœƒ(𝑒)}

22

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

cylindrical: π‘₯ = π‘Ÿ cos πœƒ, 𝑦 = π‘Ÿ sin πœƒ

spherical: π‘₯ = π‘Ÿ sin πœ‘ cos πœƒ, 𝑦 = π‘Ÿ sin πœ‘ sin πœƒ, 𝑧 = π‘Ÿ cos πœ‘ and the corresponding syntax in Cemmath is plot .@u[n=51,g=1](a,b) ( <<opt>>, x(u),y(u),z(u) ) // 3 functions plot .@u[n=51,g=1](a,b) ( <<opt>>, r(u),t(u),z(u) ) .cyl // 3D curve plot .@u[n=51,g=1](a,b) ( <<opt>>, r(u),p(u),t(u) ) .sph // 3D curve

It should be noted that Stem must have 3 functions. When Stem has 2 functions, a curve in 2D will be plotted, and an error will occur otherwise. A large number of Spokes used in 2D are also applicable to curves in 3D. Several new Spokes are provided to take care of 3D geometries. Among those are

.

cyclic (X,Y,Z) = (z,x,y)

.

cyclic .

cyclic (X,Y,Z) = (y,z,x)

.

zlog (X,Y,Z) = (x,y,log10(z))

.

zmove (c) (X,Y,Z) = (x,y,z+c)

.

zscale (sz, c=0) (X,Y,Z) = (x,y,c+sz(z-c))

.

move (a,b,c) (X,Y,Z) = (x+a,y+b,z+c)

.

psym (a,b,c,d) plane symmetry ax+by+cz=d (cf. ax+by+c=0 in 2D)

.

scale (sx,sy,sz) @(xo,yo,zo) (X,Y,Z) = (xo+sx(x-xo),yo+sy(y-yo),zo+sz(z-zo))

.

xrot (t ) @(xo,yo,zo) rotation around x-axis passing (xo,yo,zo)

.

yrot (t ) @(xo,yo,zo) rotation around y-axis passing (xo,yo,zo)

.

lrot (t, a,b,c) @(xo,yo,zo) rotation about line direction (a,b,c)

.

cosrot ( a,b,c) @(xo,yo,zo) rotation from (0,0,1) to (a,b,c)

Whether a certain Spoke is applied to 2D or 3D geometries can be determined by counting the number of arguments. For example, ".

move(a,b) " is for 2D, while ".

move(a,b,c) " is for 3D.

Multiple 3D curves can be plotted by using ‘ plot+ ’. Figure 19 shows a curve where Spoke ‘ yrot ’ (rotation around the 𝑦 -axis) is applied

#> plot .@t[501](0,5) ( exp(0.6*t), 30*t, 10*t )

.cyl.move(0,30,0) .yrot(pi/6);

#> plot+ .@t[501](0,5) ( exp(0.6*t), 30*t, 10*t ) .cyl.yrot(-pi/6); // (r,t,z)

23

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 19 3D curve

The axis plane is always shown by default. The axis plane in the screen can be hidden by placing the mouse on the screen and typing ‘a’ in the keyboard.

Subsequently, typing ‘b’ in the keyboard helps to change the color of background and typing ‘x’ in the keyboard helps to change the color of the axis planes. Zooming in and out can be also handled by the mouse wheel located in the center of the mouse. A view angle can be also modified by placing the mouse in the plot window and moving the mouse properly.

In Figure 20, several degrees of Chebyshev polynomials 𝑇 𝑛

(π‘₯)

are drawn.

The syntax for Chebyshev polynomial shall be discussed later.

#> plot .@t[2] (-1,1) ( t, 0, .T_0 (t) );

#> plot+.@t[51] (-1,1) ( t, 2, .T_2 (t) );

#> plot+.@t[51] (-1,1) ( t, 4, .T_4 (t) );

#> plot+.@t[101] (-1,1) ( t, 6, .T_10(t) );

#> plot+.@t[201] (-1,1) ( t, 8, .T_20(t) );

#> plot+.@t[501] (-1,1) ( t, 10, .T_40(t) );

#> plot+.@t[1001](-1,1) ( t, 12, .T_60(t) );

24

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 20 3D curves for Chebyshev polynomial 𝑇 𝑛

(π‘₯)

Figure 21 presents a bulb-like geometry generated by 3D curves by

#> plot .@t[1001](0,30*pi) ( 1, t/30, t ) .sph; // (R,P,T)

#> plot+.@t[1001](0,30*pi) ( 0.2, t, t/60 ) .cyl.move(0,0,1); // (r,t,z)

Figure 21 A bulb-like geometry drawn by 3D curves

And Figure 22 is a 3D revision of Butterfly and Rose discussed earlier.

#> (a,b) = (53,7);

#> plot .@t[501](0,2*pi*a) ( 5*sin(b*t), t, 0 ).cyl;

#> plot+.@t[501](0,10*pi) ( exp(cos(t))-2*cos(4*t)+(sin(t/12))^5, t, 3 ).cyl;

As for the curves for butterfly and rose, refer the literature cited in Figure 10.

25

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 22 3D plot of butterfly and rose

Section 2-7 Surfaces in 3D

β– 

Built-In Geometries . Commonly encountered in 3D are the sphere, ellipsoid, torus, disk and plane, and all of these geometries are installed in

Cemmath as built-in geometries with the following syntax

.

sphere [np=31,nt=31, gp=1,gt=1] (R )

.

ellipsoid [np=31,nt=31, gp=1,gt=1] (a,b,c )

.

torus [np=31,nt=31, gp=1,gt=1] (a,b )

.

disk [nr= 2,nt=31, gr=1,gt=1] (R )

.

plane [nx= 2,ny= 2, gx=1,gy=1] (a,b,c, side=1)

.

vector [scale=1, headscale=1,headangle=30](a,b,c)

.

frustum [nr=3,nt=21,nz=4, gr=1,gt=1,gz=1] (a,b,h )

.toroid(size)

.trefoil(size)

.mobius(size)

.klein (size)

Since the grid span denoted by ‘[ ]’ has all default values, it can be omitted unless one wants to change the grid property. To draw a sphere of radius 1 at origin with 21 × 21 uniform mesh, one just needs to input

#> plot.sphere[21,21](1) ; // 21 x 21 uniform mesh

26

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Then, the result can be seen in the left side of Figure 23. A 21 × 21 mesh net of a sphere can be seen in the right side of Figure 23 (typing ‘w’ in the keyboard transforms surface to mesh net).

Figure 23 A sphere of radius 1 at the origin.

By utilizing ‘ .hold

’, we can draw a series of spheres located around a circle. The following commands

#> n = 21;; r = 1;;

#> .hold; for.i(0,9) plot .sphere[n,n](r) .move(4*cos(i*2*pi/10),4*sin(i*2*pi/10),0) ;

#> plot; result in Figure 24.

Figure 24 Spheres of radius 1

Figure 25 shows three torus as well as an ellipsoid rotated around the 𝑧 -axis

27

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

created by

#> n = 21;; (a,b) = (4,1);;

#> .hold;

plot .torus[n,n](a,b) ;

plot .torus[n,n](a,b).cyclic.move(0, 5,0);

plot .torus[n,n](a,b).cyclic.move(0,-5,0);

#> plot;

#> (a,b,c) = (8,3,2);;

#> plot .ellipsoid(a,b,c).zrot(pi/6);

// plot.sphere(1).scale(8,3,2).zrot(pi/6)

Figure 25 Three torus and an ellipsoid

The built-in geometry ‘ disk ’ is generated in the π‘₯𝑦 –plane, as shown in Figure

26a; see the following command

#> plot .disk(1).xscale(2);

Also, a plane with a side-length 1 and a normal direction (1,1,1) can be generated by

#> plot .plane(0,0,1).cosrot(1,1,1).togo(P); P; // same as plot.plane(1,1,1); where the result is shown in Figure 26b. Examining the vertex data in the variable ‘P’

P =

28

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

[ -0.28868 -0.28868 0.57735 ]

[ -0.5 0.5 0 ]

[ 0.5 -0.5 0 ]

[ 0.28868 0.28868 -0.57735 ] clearly reveals that all the points are indeed perpendicular to (1,1,1).

Figure 26 An enlarged disk and a plane

In addition, Figure 27 shows a pyramid and a conical frustum (cones with top cut off) generated by the built-in geometry ‘ frustum ’

#> plot .frustum[5,26,9] ( 2,1,3 );

//frustum[nr=3,nt=21,nz=4, gr=1,gt=1,gz=1](a,b,h);

#> plot+.frustum[2, 5,2] ( 2,0,3 ).xmove(5);

Figure 27 Frustums

29

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

β– 

Parameterized Surfaces . In the three-dimensional space, a surface can be parameterized with the aid of two parameters and 𝑐(𝑒) ≤ 𝑣 ≤ 𝑑(𝑒) parameterized surface reads 𝑒, 𝑣 for which π‘Ž ≤ 𝑒 ≤ 𝑏 may be specified. The standard form of the π‘₯ = π‘₯(𝑒, 𝑣), 𝑦 = 𝑦(𝑒, 𝑣), 𝑧 = 𝑧(𝑒, 𝑣)

Then, the parameterized surface can be plotted by the following Cemmath command plot .u[nu=31,gu=1](a,b) .v[nv=31,gv=1](c(u),d(u))

( <<opt>>, x(u,v),y(u,v),z(u,v))

Unlike the parameterized curves utilizing the character ‘ @ ’, the parameterized surfaces do not adopt ‘ @ ’ to represent parameterization. This is because three expressions are always included inside the Stem. The Cemmath is wise enough to distinguish whether a parameterized surface is described or not by counting the number of Hub variables as well as the number of expressions inside the Stem.

On the contrary to the case of 2D, it is crucial to remember that the

Umbrella ‘ plot ’ can draw only 1 surface at a time. Whenever multiple surfaces are desired in one layout, ‘ plot+ ’ must be used for each surface.

One of the striking features of Hub is that it can handle multidimensionality with ease. In the above, the Hub is composed of two grid spans in both 𝑒 and 𝑣 directions. Since the grid span in each spatial coordinate is separated by dot, it is extremely easy to grasp the range of grid span in each direction. Furthermore, the second grid span can have functions in terms of the variable defined in the first grid span.

β– 

Surfaces 𝑧 = 𝑧(π‘₯, 𝑦) For example, a surface given by the following

−3 ≤ π‘₯ ≤ 3, − √10 − π‘₯ 2 𝑧 = (π‘₯ 2

≤ 𝑦 ≤ 3 + π‘₯

+ 𝑦 2 ) exp(1 − π‘₯ 2 − 𝑦 2 ) can be easily generated by the input

30

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

#> plot .x[21](-3,3) .y[21](-sqrt(10-x*x), 3+x) ( (x*x+y*y)*exp(1-x*x-y*y) ); and the result with 21 × 21 mesh grid is shown in Figure 28. Remember that the grid mesh is 51 × 51 by default.

Figure 28 3D surface z

ο€½

( , )

β–  Surfaces 𝑧 = 𝑧(π‘Ÿ, πœƒ) in the polar coordinate . When the π‘₯𝑦 -plane is expressed in terms of the polar coordinate (π‘Ÿ, πœƒ) , implementing this case just requires a use of the Spoke ‘ cyl ’. plot .u[nu=31,gu=1](a,b) .v[nv=31,gv=1](c(u),d(u)) ( <<opt>>, r,t,z).cyl where r(u,v),t(u,v),z(u,v) are functions of 𝑒 and 𝑣 .

For example,

#> plot.r[41](0,5) .t[21](0,3*pi/2) ( r,t,sin(r*r) ) .cyl;

#> plot.t[21](0,3*pi/2) .r[41](0,5) ( r,t,sin(r*r) ) .cyl; corresponds to the result shown in Figure 29.

31

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 29 A surface in the polar coordinate

β– 

Surfaces in the spherical coordinate . When the azimuthal πœ‘ and cone πœƒ angles are used to define a surface π‘Ÿ = π‘Ÿ(πœ‘, πœƒ) , the corresponding syntax becomes plot .u[nu=31,gu=1](a,b) .v[nv=31,gv=1](c(u),d(u)) ( <<opt>>, r,p,t).sph where r(u,v),p(u,v),t(u,v) are functions of 𝑒 and 𝑣 .

The coordinate transformations π‘₯ = π‘Ÿ sinπœ‘cosπœƒ, 𝑦 = π‘Ÿsinπœ‘ sin πœƒ, 𝑧 = π‘Ÿ cos πœ‘ are handled internally. It should be noted that the cone angle must appear first to keep the right-hand rule. Figure 30 illustrates two interesting geometries, a wrinkled sphere and a bumpy sphere (see ref [3]). The mathematical expressions for π‘Ÿ = π‘Ÿ(πœ‘, πœƒ) are already included in the figure, and thus are not repeated.

#> plot.p[21](0,pi).t[51](0,2*pi) ( 1+0.2*sin(8*t)*sin(p) ,p,t ).sph;

#> plot.p[41](0,pi).t[51](0,2*pi) ( 1+0.2*sin(8*t)*sin(4*p),p,t ).sph;

32

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 30 Surfaces in the spherical coordinates

β–  General Parameterized Surfaces . In Figures 31-36, several interesting parameterized surfaces are plotted. Since the mathematical expressions are all together specified in the corresponding figure, they are not repeated here.

#> (a,b) = (4,2);

#> plot.u(0,pi).v(-1,1) ( #> plot.u(-pi,pi).v(-pi,pi) (

(a-v*sin(u))*cos(b*u), sin(u)*(7+cos(u/3-2*v)+2*cos(u/3+v)),

(a-v*sin(u))*sin(b*u), cos(u)*(7+cos(u/3-2*v)+2*cos(u/3+v)), v*cos(u) ); sin(u/3-2*v)+2*sin(u/3+v) );

Figure 31 Mobius strip [3] Figure 32 Umbilic torus [3]

#> plot.u(-pi,pi).v(-pi,pi) (

3+sin(u)*(7-cos(3*u-2*v)-2*cos(3*u+v)),

3+cos(u)*(7-cos(3*u-2*v)-2*cos(3*u+v)), sin(3*u-2*v)+2*cos(3*u+v) );

Figure 33 Strip with multiple twists [3]

33

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

#> plot.u(-pi,pi).v(-pi,pi) (

3+sin(u)*(7-cos(3*u-2*v)-2*cos(3*u+v)),

3+cos(u)*(7-cos(3*u-2*v)-2*cos(3*u+v)) , sin(3*u-2*v)+2*sin(3*u+v) );

Figure 34 Double strips [3]

#> plot .u(0,2*pi).v(0,2*pi) (

<< a = 2-cos(u), b = a*cos(v),

xu = 3*cos(u)*(1+sin(u)), yu = -8*sin(u) >>,

u < pi ? xu + b*cos(u) : xu-b,

u < pi ? yu - b*sin(u) : yu,

-a*sin(v)

);

Figure 35 Klein bottle

34

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

(a,b,c,d) = (0.5, 0.3, 0.5, 0.1);;

plot .u[51](0,2*pi).v[7](0,2*pi) (

<< r = a + b*cos(3*u),

vp = < r*cos(2*u), r*sin(2*u), c*sin(3*u) >,

vq = < -1.5*b*sin(3*u)*cos(2*u) - vp.y,

-1.5*b*sin(3*u)*sin(2*u) + vp.x,

1.5*c*cos(3*u) > .unit,

vn = < vq.y, -vq.x, 0 > .unit,

vq ^= vn

>>,

vp + d*( vn*cos(v) + vq*sin(v) ) // vertex

);

Figure 36 Trefoil knot

Section 2-8 Revolution in 3D

β– 

Revolution around a line . A large amount of mathematically important surfaces can be generated by revolution around a certain line, for example the π‘₯ -axis. Cemmath provides such geometries by means of Spokes summarized below.

.xrev [nt=21,gt=1](t1=0,t2=2*pi)

.yrev [nt=21,gt=1](t1=0,t2=2*pi)

.zrev [nt=21,gt=1](t1=0,t2=2*pi)

.lrev [nt=21,gt=1](t1,t2 a,b,c) line ax+by+c=0

Much like the grid spacing treated so far, the spanning properties 𝑛, 𝑔 are placed within ‘[ ]’. In generating a revolution surface, only a single connected curve in the π‘₯𝑦 -plane can be used as a generating curve, and only one revolution surface is obtained thereby. Note especially that the rotation around the 𝑧 -axis always creates a flat surface. The range of rotation angle can be selected at users’ choice between 0 and 2πœ‹ . A few examples are listed below.

#> plot.star(1).move(0,2) .xrev(0,pi); // xrev[21,1](0,2*pi)

#> plot.x[11](-1,1) ( x^3 ) .yrev. cyclic;

#> plot.x[10](pi,2*pi) ( sin(x) ) .zrev[11](0,pi) ;

#> plot.t[21](0,2*pi) (1).cyl.move(2,1).lrev(0,2*pi, 1,1,0); // line x+y = 0

35

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

and the results are displayed in Figures 37-40.

#> plot.star(1).move(0,2) .xrev(0,pi); // xrev[21,1](0,2*pi,0)

#> plot.x[11](-1,1) ( x^3 ) .yrev. cyclic;

Figure 37 Revolution around x-axis Figure 38 Revolution around y-axis

#> plot.x[10](pi,2*pi) (sin(x)).zrev[11](0,pi);

#> plot.t[21](0,2*pi) (1).cyl.move(2,1).lrev(0,2*pi, 1,1,0);

Figure 39 Revolution around z-axis Figure 40 Revolution around a line

When multiple surfaces intersect one another, hidden surfaces cannot be shown.

This can be seen by the following commands

#> plot .x[2](-2,2)(1).xrev; plot+.x[2](-2,2)(1).xrev .zrot(pi/2); plot+.x[2](-2,2)(1).xrev .yrot(pi/2); and the results are shown in Figure 41.

36

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 41 Intersecting surfaces

β–  Revolution with Closed Ends . When a single connected curve is revolved around a given line, the surface may be open at both ends. To cover open ends, we use two Spokes discussed above

.side1[n=3,g=1] // starting-side closing

.side2[n=3,g=1] // ending-side closing

An example of revolution surface with closed ends is

#> plot .x[21](0,2) ( exp(-0.5*x) ) .xrev .side2;

#> plot .x[3]( 1, 2)( x) .xrev.side1.side2;

#> plot+.x[3]( 1, 2)( x) .yrev.side1;

#> plot+.x[3](-2,-1)(-x) .xrev.side2;

#> plot+.x[3](-2,-1)( x) .yrev.side2; and the result is in Figure 42. Remember that ‘ xrev[21,1](0,2*pi) ’ is the same as

‘ xrev ’ from default options.

37

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 42 Revolution with one closed end

One interesting feature of revolution with sides is that a pyramid can be also drawn. When the grid size of rotation is 5, angle spacing becomes 360/(5-

1)=90, and one side of rotation looks like a square. Therefore, the following command

#> plot.x[6](0,1) ( 1-x ) .xrev[5] .side1; creates a pyramid shown in Figure 43.

Figure 43 A pyramid (top and bottom view)

Figure 44 illustrates the case of using the upper-step or lower-step function, given by

#> plot.x[13](-pi,2*pi) ( 3+cos(x) ) .ustep .xrev .side1 .side2;

38

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 44 Revolution of a step-function

Section 2-9 Popped and Filled Surfaces in 3D

β–  Popped Surface . A popped surface is defined here to be a surface obtained by popping the curve in the π‘₯𝑦 –plane into the 𝑧 -axis. It should be noted that only one curve can be popped by Spoke ‘ zpop ’ the syntax of which is

.zpop[nz=3,gz=1] (height,ratio=1)

An example of popped surfaces are obtained by

#> plot .x[21](0,2*pi) (sin(x)) .zpop[5](2);

#> plot+ .star(1) .move(0.5*pi,0) .zpop(2);

#> plot+ .star(1) .zpop(2,0.5).move(1.5*pi,0,0); and is displayed in Figure 45.

39

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 45 Popped surfaces from 2D curve

β–  Popped Surfaces with Sides . Any single curve in the π‘₯𝑦 -plane can also be popped along the 𝑧 -direction with sides at bottom, top and inside. The syntax for Spoke ‘ zpop ’ is extended

.zpop[nz=3,gz=1] (height,ratio=1)

&&[nr=3,gr=1](Rb=0,Rt=0){bot=1,top=1,inside=0}

The grid in the side direction is added together with

(Rb=0,Rt=0) where Rb the relative magnitude of the bottom hole, and Rt that of the top hole.

In addition

{ bottom=1,top=1,inside=0} determines whether each end is closed or not.

The simplest case of ‘ zpop ’ would be ‘ frustum ’ discussed earlier, since

.frustum[nr,nt,nz](a,b,h) is the same as .circle[nt](a).zpop[nz](h,b/a)

&&[nr]

This can be confirmed by taking out the final data points, for example

#> plot .frustum[4,5,3](2,1,3) .togo(A);;

#> plot+ .circle[5](2).zpop[3](3,1/2) &&[4].togo(B);;

#> A-B;

The result

A-B=

[ 0 0 0 ]

[ 0 0 0 ]

40

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

[ 0 0 0 ]

[ 0 0 0 ]

[ 0 -0 0 ]

[ 0 0 0 ]

[ 2.9141e-008 0 0 ]

[ 0 1.0066e-007 0 ]

[ 0 0 0 ]

[ 0 -0 0 ] shows no difference between the final data points A and B .

Figure 46 displays the role of surface options and the effect of varying arguments very clearly.

#> T = (0,1.5*pi).span(31);;

#> .hold;

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&{1,1,0}.move(0,0,10);

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&{0,1,0}.move(8,0,10);

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&{1,0,0}.move(16,0,10);

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&{0,0,1}.move(0,0,5);

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&{1,0,1}.move(8,0,5);

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&{0,0,0}.move(16,0,5);

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&(0.2,0.2){1,1,1};

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&(0.2,0.2){0,1,1}.move(8,0,0);

plot[@T]( 3*cos(T),2*sin(T) ).zpop[6](3,0.5) &&(0.2,.2){1,1,0}.move(16,0,0);

#> plot;

41

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

Figure 46 Variation of surface options {bottom,top,inside} in Spoke

‘ zpop ’

Figure 47 displays interesting construction of 3D shapes from the well-known cardioid by

#> plot .t[31](0,2*pi) ( 1+cos(t) ) .cyl .zpop[6](0.5)&&[21](0.5,0.5){1,1,1};

#> plot+ .t[31](0,2*pi) ( 1+cos(t) ) .cyl .zpop(0.5)&&[21] .ymove(3);

Figure 47 3D Variation of cardioids in 3D

β– 

Filled Surface . A filled surface is defined here to be a surface obtained by filling two curves. It should be noted that only one filled surface can be generated by Spoke ‘ fill ’ the syntax of which is

42

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

.fill[n=21,g=1]

Of course, a filled surface is always flat and lies in the π‘₯𝑦 -plane. It is possible to move or rotate a filled surface by applying appropriate Spokes. An example of a filled surface is obtained by

#> plot.x[11](-2,2) ( x*x-4, 1+cos(x) ) .fill[11]; and is displayed in Figure 48. plot.x[11](-2,2) ( x*x-4, 1+cos(x) ) .fill[11];

Figure 48 Filled surface between two curves

Section 2-10 Summary of Syntax

In the following, the default values of ‘ @(xo,yo) ’ or ‘ @(xo,yo,zo) ’ are always xo=0, yo=0, zo=0 . The Spoke ‘ polar ’ can be alternatively used as ‘ cyl ’

(an abbreviation of cylindrical). A special character ‘ @ ’ is only used to denote parameters for 2D and 3D curves.

β–  Syntax for 2D curve(s) plot .x[n=51,g=1](xa,xb) ( <<opt>>,f(x), … ) 2D curve(s)

43

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

plot .t[n=51,g=1](ta,tb) ( <<opt>>,r(t), … ) .cyl 2D curve(s) plot .@u[n=51,g=1](ua,ub) ( <<opt>>,x(u),y(u) ) 2D curve (single) plot .@u[n=51,g=1](ua,ub) ( <<opt>>,r(u),t(u) ) .cyl 2D curve (single)

β–  Syntax for 2D Phase Diagram plot .u[n=21,g=1](a,b) .v[n=21,g=1](c(u),d(u)) ( u ' , v ' )

.phase[scale=1,headscale=1,headangle=30]

β–  Syntax for 3D curve (only a single curve) plot .@u[n=51,g=1](a,b) ( <<opt>>,x(u),y(u),z(u) ) // 3 functions plot .@u[n=51,g=1](a,b) ( <<opt>>,r(u),t(u),z(u) ) .cyl plot .@u[n=51,g=1](a,b) ( <<opt>>,r(u),p(u),t(u) ) .sph

β–  Syntax for 3D surface (only a sinlge surface) plot .u[n=31,g=1](a,b) .v[n=31,g=1](c(u),d(u)) (<<opt>>,x,y,z) plot .u[n=31,g=1](a,b) .v[n=31,g=1](c(u),d(u)) (<<opt>>,r,t,z) .cyl plot .u[n=31,g=1](a,b) .v[n=31,g=1](c(u),d(u)) (<<opt>>,r,p,t) .sph where

x=x(u,v), y=y(u,v), z=z(u,v)

r=r(u,v), t=t(u,v), z=z(u,v)

r=r(u,v), p=p(u,v), t=t(u,v)

β–  Built-in geometries in 2D

.circle [nt=51,gt=1] (radius)

.ellipse [nt=51,gt=1] (a,b )

.polygon [nvert,gt=1] (radius) // nvert >= 3

.triangle (a,b,c )

.square (a )

.rectangle (a,b )

.parallel (a,b, theta )

.trapezoid (a,b, height)

.star (radius )

.point (a,b)

44

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

.line (x1,y1, x2,y2)

.vector [scale=1,headscale=1,headangle=30] (a,b)

β– 

Built-in geometries in 3D

.sphere [np=31,nt=31, gp=1,gt=1] (R )

.ellipsoid [np=31,nt=31, gp=1,gt=1] (a,b,c )

.torus [np=31,nt=31, gp=1,gt=1] (a,b )

.disk [nr= 2,nt=31, gr=1,gt=1] (R )

.plane [nx= 2,ny= 2, gx=1,gy=1] (a,b,c, side=1)

.frustum [nr=3,nt=21,nz=4, gr=1,gt=1,gz=1] (a,b,h)

.vector [scale=1,headscale=1,headangle=30] (a,b,c)

.line (x1,y1,z1, x2,y2,z2)

.toroid(size)

.mobius(size)

.klein(size)

.trefoil(size)

β– 

Spokes common

.xlog X = log10(x) in plot (no change in data)

.ylog Y = log10(y) in plot (no change in data)

.xsym(a=0) X=2*a-x symmetry about line x=a

.ysym(b=0) Y=2*b-y symmetry about line y=b

.xmove(a) X=x+a translate in x-direction by a

.ymove(b) Y=y+b translate in y-direction by b

.xscale(sx,a=0) X=a+sx*(x-a) elongate in x-dir about line x=a

.yscale(sy,b=0) Y=b+sy*(y-b) elongate in y-dir about line y=b

.xmean(xm) extracts a mean value of x

.ymean(ym) extracts a mean value of y

.togo(A) extracts matrix A for data points plot; draw a plot immediately plot+.hold; hold+; hold the current plot for overwriting

.hold; new and hold

β– 

Spokes for 2D curves

.cyl must be the first Spoke

45

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

.flip (X,Y)=(y,x) symmetry about line y = x

.loglog (X,Y)=(log10(x), log10(y))

.move(a,b) (X,Y)=(x+a,y+b) translate by a vector (a,b)

.osym @(xo,yo) (X,Y)=(2*xo-x,2*yo-y) symmetry about point (xo,yo)

.scale(sx,sy)@(xo,yo) (X,Y)=(xo+sx*(x-xo),yo+sy*(y-yo))

.zrot(t) @(xo,yo) rotate counterclockwise about (xo,yo)

.lsym(a,b,c) symmetry with respect to line ax+by+c = 0

.lstep lower-step function

.ustep upper-step function

.xstem stem with respect to the x-coordinate

.ystem stem with respect to the y-coordinate

.xystem stem with respect to the x- and y-coordinates

.stem stem with circle

.merge make all curves to be a single curve

.link connect piecewise curves

.movelink connect piecewise curves to the last ending point

.copy[n] (dx,dy) duplicate n curves and move by (dx,dy)

.copylink[n] (dx,dy) copy[n](dx,dy) and make all curves to be a single curve

.allout(A) extracts matrix A for all the vertex data

.info print out information on curves and vertex

.xrev [nt=21,gt=1](t1=0,t2=2*pi, a=0)

.yrev [nt=21,gt=1](t1=0,t2=2*pi, b=0)

.zrev [nt=21,gt=1](t1=0,t2=2*pi, c=0)

.lrev [nt=21,gt=1](t1,t2 a,b,c) line ax+by+c=0

.zpop [nz= 3,gz=1](h,ratio=1) &&[nr=3,gr=1]

(Rb=0,Rt=0){bottom=1,top=1,inside=0}

.fill [nf=21,gf=1]

β– 

Spokes for 3D curves and surfaces

.cyl must be the first Spoke

.sph must be the first Spoke

.zlog Z=log10(z)

.zmove(c) Z=z+c

.zscale(sz, c=0) Z=c+sz*(z-c)

.zsym (c=0) Z=2*c-z symmetry about plane z=c

.psym(a,b,c,d) plane symmetry ax+by+cz=d

.zmean(zm) extracts a mean value of z

.cyclic (X,Y,Z)=(z,x,y)

46

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

.move(a,b,c) (X,Y,Z)=(x+a,y+b,z+c)

.osym @(xo,yo,zo) (X,Y,Z)=(2*xo-x,2*yo-y,2*zo-z) point symmetry

.scale(sx,sy,sz) @(xo,yo,zo) (X,Y,Z)=(xo+sx(x-xo),yo+sy(y-yo),zo+sz(z-zo))

.xrot (t ) @(xo,yo,zo) rotation around x-axis passing (xo,yo,zo)

.yrot (t ) @(xo,yo,zo)

.zrot (t ) @(xo,yo,zo)

.lrot (t, a,b,c) @(xo,yo,zo) rotation about line direction (xo,yo,zo)

.cosrot( a,b,c) @(xo,yo,zo) rotation from (0,0,1) to (xo,yo,zo)

β– 

More Spokes Discussed in Chapter 3

.int1da (f(x,y)) (fscalar) .intxxda(f(x,y)) (fscalar)

.intxda (f(x,y)) (fscalar) .intxyda(f(x,y)) (fscalar)

.intyda (f(x,y)) (fscalar) .intyyda(f(x,y)) (fscalar)

.intdl (f(x,y,z), … ) (fscalar, …)

.intda (f(x,y,z), … ) (fscalar, …)

.intdL * (Fx(x,y,z),Fy(x,y,z),Fz(x,y,z)) (fscalar)

.intdL ^ (Fx(x,y,z),Fy(x,y,z),Fz(x,y,z)) (Fmatrix)

.intdL (f(x,y,z)) (Fmatrix)

.intdA * (Fx(x,y,z),Fy(x,y,z),Fz(x,y,z)) (fscalar)

.intdA ^ (Fx(x,y,z),Fy(x,y,z),Fz(x,y,z)) (Fmatrix)

.volume(vol)

.intdA (f(x,y,z)) (Fmatrix)

.area(area)

Section 2-11 References

[1] P.M. Maurer, A rose is a rose ..., Math. Monthly, 94 (1987), pp. 631-645.

[2] T.H. Fay, A study in step size, April issue, Mathematics Magazine (1997).

[3] R.E. Larson, R.P. Hostetler, B.H. Edwards, Calculus with Analytic Geometry,

6ed.,

Houghton Mifflin Co., (1998)

[4] MATLAB Ⓡ 7, Mathematics, The MathWorks Inc. (2009).

47

[100] 002 Chapter 2 Plot, Tutorial by www.msharpmath.com

[5] D.J. Higham and N.J. Higham, MATLAB(R) Program GuideBook, 2ed., SIAM

(2005).

//----------------------------------------------------------------------------

// end of file

//----------------------------------------------------------------------------

48

Download