Creating Graphics Using the Function "mkgraph"

The function "mkgraph" is "E"-type function, used to create a graph or a plot. The result will be rendered as a Java applet.

Syntax

mkgraph(width,height,functions,xmin,xmax,ymin,ymax,par1,par2,...)
Arguments:
width (Numeric)
The applet's width in pixels.
height (Numeric)
The applet's height in pixels.
xmin, xmax (Numeric)
The range of values for the x-axis.
ymin, ymax (Numeric)
The range of values for the y-axis.
functions (String)
A functional expressions of the variable x to be plotted, or a semicolon separated list of such expressions. See optional parameter "Functions" for more details.
Examples:
    3x^2-4x+2
    x^2;x^3;x^4;x^5
par1, par2, ... (Strings)
Optional Parameters.
Syntax
"name = value "     or
"name = value1; value2; ..."
Examples
scale=auto
colors=0000ff;ff0000;00ff00;ffcc00
linestyle=0;0;2;1
For details, see Optional Parameters below.

Optional Parameters

There are several categories optional parameters.

CategoryParameter names
Titles and labels plottitle, xtitle, ytitle, xlabel, ylabel, and axes.
Drawing objects func, polygon, swarm.
Functions and Polygons properties linestyle, colors, legend, and notation.
Grid and scale display grid, coord, selfticks, xticks, yticks, and scale.
Points and text labelspoints and text
User Defined Functionregister.

Titles and labels

plottitle=Plot-Title-Text
Title to appear at the top of the graph.
xtitle=x-axis-title
Will display along the x-axis.(Only if axes is "on")
ytitle=y-axis-title
Will display along the y-axis, going upward. (Only if axes is "on")
xlabel=short-text
Will appear at the end of x-axis. Usually short-text is "x" or "t" used for
the argument name.
ylabel=short-text
Will appear at the end of y-axis, Usually short-text is "y" or other letter
used for the function name.
axes=on
axes=off
Show or hide the display of the lines x=0 and y=0, provided the lines are in
the visible range. Affects also xlabel, xtitle,ylabel,ytitle parameters.

Functions

Appends the list of functional expressions of the variable x to be plotted, given in the "functions" argument.
Syntax:
func = expression
func = expression1; expression2; ...
For details on expression, see Entering Expressions below.
Examples
func = 3x^2-4x+2
func = x^2;x^3;x^4;x^5
func = 3x^2-4x+2;x^2+2;x*sin(x^2)
func = f(x);f(x+1)-g(x-1);h(x)
Remark 1. Last example assumes that f,g, and h are user defined functions defined within register parameter.
Remark 2. You can control the color, linestyle, and the legend notation of the functions, using the global "colors", "linestyle" and "notation" parameters.
Remark 3. You can control the number of points in which the function(s) will be calculated, by using the parameter "numfp.

Polygon (connected line segments)

Draws one or more sets of sequential line segments.
Syntax:
polygon = points_data
polygon = points_data1; points_data2; ...
where each points_data uses one of the following formats
(x1,y1)
(x1,y1):vertices
(x1,y1):(x2,y2):...: (xn,yn)
(x1,y1):(x2,y2):...: (xn,yn):vertices
In the above (xk,yk) are the coordinates of each vertex in the xy-coordinates system
(not screen pixels). The optional vertices is ether "yes" or "no", and controls the display of small rectangles at the position of the polygon vertices.
Remark. You can control the color, linestyle, and the legend notation of the polygon, using the global "colors", "linestyle" and "notation" parameters.

Functions and Polygons properties

These properties use semicolon separated list, common for functions and polygons.
The values are ordered by listing all functions first, and then all polygons.
 
linestyle=style1;style2;...stylen
where each style is one of the numbers 0,1, or 2 representing "solid line style", "dashed line style", and "dotted line style" respectively.
 
colors=color1;color2;...colorn
where each color is 6 hexadecimal lowercase digits, for example "red" is ff00000, "green" is 00ff00, and "blue" is 0000ff.
Using "colors" parameter will change the color of ALL functions and polygons.
The colors can be repeated.
 
legend=on
legend=off
Show or hide the legend (list of colored rectangles with functions/polygons names.)
 
notation=name1;name2;...namen
where each name should be very short string with a name for a function or polygon for the legend. If the name is empty, the complete line from the legend is removed. Will be used only when the "legend" is "on".
 
numfp=NUMBER
where NUMBER is in integer between 5 and 1000 with default value of 200. This parameter controls how many values of the function(s) to calculate for the graph. The parameter applies to all functions, but not to polygons or other objects like swarm.

The parameter "swarm". (Advanced.)

Draws one or more sets of line segments. Primary used for parametric plots, polar plots, graphs of inverse functions, and other special plots.
Syntax:
swarm = swarm_data
swarm = swarm_data1; swarm_data2; ...
where each swarm_data has following format:
x1(t):y1(t):x2(t):y2(t):a:b:n:color
Here each of x1(t), y1(t), x2(t), and y2(t) is a functional expressions of the variable t. (See Expressions for details.) The numbers "a" and "b" define the interval [a, b] for the parameter t. The number "n" controls the number of line segments in the set. The drawing color is determined by the hexadecimal number color.
Implementation:
For each ti = a + i*(b-a)/n, i=0,1,...n,
the points (x1(ti),y1(ii)) and (x2(ti),y2(ii)) are connected with a color-colored line segment.
Examples:
   1. Draw the graph of function f(x)=x^3+x^2-1 and its inverse.
register= f(u):=u^3+u^2-1;
func= f(x)
swarm= f(t):t:f(t+0.04):t+0.04:-1:1:50:ff0000
Remark. Since (b-a)/n is exactly 0.04, the graph is continuous line. To emulate dashed line one can use 0.02 instead.
   2. Draw the graph of the parametric curve (cos(3t),sin(5t)), 0 ≤ t ≤ 2π.
register= f(t):=cos(3t);g(t):=sin(5t);tn(t):=t+0.01256;
swarm= f(t):g(t):f(tn(t)):g(tn(t)):0:6.28:500:0000ff
Remark. Since the length of this curve is very big we need much higher n=500. Again 0.01256=(b-a)/n.
   3. Draw the polar graph r(θ)=(cos(θ)-1)/2, 0 ≤ θ ≤ 2π.
register=r(t):=(cos(t)-1)/2;px(t):=r(t)cos(t);py(t):=r(t)sin(t);tn(t):=t+0.1256;
swarm=px(t):py(t):px(tn(t)):py(tn(t)):0:6.28:50:0000ff;

Grid and scale display

grid=on
grid=off
Show or hide the lines connecting the border ticks.
coord=on
coord=off
Show or hide the numbers for the border ticks.
selfticks=no
Calculate the values for the ticks, based on the scale parameter.
This is the default value for selfticks
scale=auto
Calculate the values the ticks, based on the intervals [xmin, xmax],
and [ymin, ymax], and the pixel dimensions of the plot.
This is the default value for scale.
scale=x-length,y-length
where x-length and y-length are numbers. To find the ticks, the interval [xmin, xmax] is split into pieces with length x-length, and the interval [ymin, ymax] is split into pieces with length y-length.
selfticks=yes
Use explicit values for the ticks, provided by the parameters xticks, and yticks.
xticks=value1,value2,...,valuen
where each value is a number from [xmin, xmax] interval.
yticks=value1,value2,...,valuen
where each value is a number from [ymin, ymax] interval.

Points and text labels

points=point1;point2;...;pointn
where each point uses the following format
(x,y):Label:Color
where x and y are the coordinates, (in the [xmin,xmax]×[ymin,ymax] system)
Label is short text, for example A(-2,2)
Color is 6 hexadecimal digits (see colors).
Example:
points=(5.0,2.3):A(5.0,2.3):ff0011;(4.0,5.7):M(4.0,5.7):ff00ff
text=label1;label2;...;labeln
where each label uses the following format
(x,y):Text
where x and y are the coordinates, (in the [xmin,xmax]×[ymin,ymax] system)
Text is any string. There is no wrap at border.
Example:
text=(3,3.4):This is a text label;(-9,3.6):This is another text label

Entering Expressions

An expression can include numbers and constants, variables, operations, standard functions and user defined functions. Any number of blanks and parentheses may be used to make the expression more readable.

The numbers are written as integers (143), as numbers with fixed decimal point (3.12) or using scientific notation (1.234E-11).

There are two predefined constants: pi=3.14159... and e=2.71828....

All standard algebraic operations, like addition '+', subtraction '-', multiplications '*', division '/' and power '^' (or '**') are allowed. The multiplication sign "*", and the parenthesis for function argument, can be omitted, in the obvious cases.

For a list of the standard function, see "Standard Functions" below.
For user defined functions see "User Defined Functions" below.
For piecewise defined functions see "The Function case" below.

Examples:

2*(x+1)^2-(3/4)^0.5 2(x+1)^2-sqrt(3/4)
exp(cos(-x+pi/2)) |1+x|ln(1+x)
case(x<0,-1,x>0,1,0) sum(i:=0,6,x^i)-1/(1-x)

 

User Defined Functions and register parameter.

You can define your own functions, that can be used in expressions, the same way as the standard functions. User functions are submitted using the register optional parameter, using one of the following formats:
register=definition
register=definition1; definition2; ... ;
Each user function definition has the following syntax:
function_name(variables):=expression
function_name():=expression
The parts are:
function_name
A name for the function, starting with letter, and containing only letters or digits. It cannot match standard or (other) used defined function name.
variables
A variable name or comma separated list of variable names, used in the expression. Variable names are usually one letter, and no name could match standard or used defined function name.
expression
Could be any expression, containing constants, the function's variable name(s), standard functions, or already defined user functions.
Examples:
register = f1(x):=x+4; f2(x):=4-x; f3(x):=f1(x)*f2(x);
register = n(x,y):=sqrt(x^2+y^2); n3(x,y,z):=n(x,n(y,z));
register = px(t):=4cos(3t); py(t):=3sin(7t);
register = pi4():=pi/4; f(x):=sin(x+pi4())

 

Standard Functions

Function Description
Trigonometric Functions
sin(x) Returns the sine of x.
cos(x) Returns the cosine of x.
tan(x) Returns the tangent of x.
acos(x) Returns the arccosine of x (in radians).
asin(x) Returns the arcsine of x (in radians).
atan(x) Returns the arctangent of x (in radians).
Hyperbolic Functions
sinh(x) Returns the hyperbolic sine of x.
cosh(x) Returns the hyperbolic cosine of x.
tanh(x) Returns the hyperbolic tangent of x.
acosh(x) Returns the hyperbolic arccosine of x (in radians).
asinh(x) Returns the hyperbolic arcsine of x (in radians).
atanh(x) Returns the hyperbolic arctangent of x (in radians).
Exponential and Logarithmic Functions
exp(x) Returns ex, where e is Euler's constant. Can be written as “e^x”.
ln(x) Returns the natural logarithm (base e) of x.
pow(a,x) Returns a to the power x, that is, ax. Can be written also as “a^x”.
log(b,x) Returns the logarithm base b of x.
root(N,x) Returns the value of the Nth root of x.
Other Functions
abs(x) Returns the absolute value of x. Can be written also as |x|.
sqrt(x) Returns the square root of x. (x should be non-negative.)
arg(x,y) Returns the arctangent of the quotient “y/x”.
ceil(x) Returns the smallest integer greater than or equal to x.
floor(x) Returns the largest integer less than or equal to x.
round(x) Returns the value of x rounded to the nearest integer.
max(x,y) Returns the greater of two numbers.
min(x,y) Returns the lesser of two numbers.
random Returns a pseudo-random integer number between 0 and 1.
sum(i:=a,b,expr) Returns the sum of the expr evaluated for i=a, i=a+1, ..., i=b.
prod(i:=a,b,expr) Returns the product of the expr evaluated for i=a, i=a+1, ..., i=b.

The Function case (Piecewise Defined Functions)

The function case has one of the following forms:

case(COND,TRUE,FALSE)     or
case( COND1,TRUE1, COND2,TRUE2,... CONDn,TRUEn,FALSE)

where COND are relational expressions, and TRUE and FALSE are expressions.

The first form of case will be evaluated as the result of the expression TRUE, provided COND is true, and as the result of the expression FALSE otherwise.

The second form of case can be read as
If COND1 is true, return the result of TRUE1.
Else if COND2, return the result of TRUE2
...
If no one of the COND is true, return the result of FALSE.

A relational expression is an inequality (relation) between two expressions, a chain of inequalities or result of a logical operation between relational expression.

 

Symbols used in relations
SymbolDescription
< less than
> greater than
= equal to
<= less than or equal
>= greater than or equal
= not equal
Logical operations
|| or
&& and

Examples:
case(x<0,-x,x)
The expression will be evaluated as -x for negative x and as x for non-negative x.
The same function can be written as abs(x) or |x|.

Each of the following expressions represents a function equal to sin(x),
when x in the interval [0,pi], and equal to 0 otherwise.
case( 0 <= x <= pi , sin(x), 0 )
case( (0 <= x) && (x <= pi) , sin(x), 0 )
case( x > pi , 0, x < 0 , 0 , sin(x) )
case( x < 0 , 0, x > pi , 0 , sin(x) )
case((x<0)||(x>pi),0,sin(x))

The function sin(x) with an amplitude restricted at level 0.5 can be written as:
case( -0.5 > sin(x) , -0.5, sin(x) > 0.5 , 0.5, sin(x))

 



WorldWideTestbank™ ©1998- Link-Systems International, Inc