Topic 6. Functions. Procedures Expansion Packages. 2D graphics
Site: | Навчально-інформаційний портал НУБіП України |
Course: | Computers and Computer Technology (БЦІ). P2 ☑️ |
Book: | Topic 6. Functions. Procedures Expansion Packages. 2D graphics |
Printed by: | Гість-користувач |
Date: | Tuesday, 13 May 2025, 3:07 AM |
1. Functions
Function (mapping, operator, transformation) is a mathematical concept that reflects the connection between the elements of sets.
The function is the rule by which each element of one set (domain of definition) corresponds to some element of another set (domain of values).
Often, the term "function" is understood as a numerical function - when one number corresponds to another.
The term "function" was introduced by Leibniz (1692).
Distinguish functions:
- depending on variables - one variable, many variables, etc .;
- the form of presentation - tabular, analytical;
- look - algebraic, trigonometric, etc.
Functions in computer systems are usually divided into four types:
- embedded in the core of the system;
- user functions;
- library functions from packages or from extension libraries;
- functions that are specified as a program module.
Maple has a large set of standard math functions, both elementary and special (tab.).
Function | Maple syntax |
|
Function |
Maple syntax |
e x |
exp (x) |
|
sqrt (x) |
|
ln (x) |
ln (x) or log (x) |
|
abs (x) |
|
|
log10 (x) |
sgn (x) |
signum (x) |
|
|
log [a] (x) |
n! |
n! or factorial |
Definition of functions
In Maple, there are several ways to define functions:
- Assigning a variable to a certain expression, for example: F0: = cos (t) +1;
- with the help of a functional operator the function name: = list of parameters -> expression; for example: F1: = (x, y) → x (y ^ 2);
- using the unapply command (expression, parameters) that converts the expression into a functional operator, for example, F2: = unapply (F0, t);
- using the statement define (operator, property1, property2, ...) .
In the first case, an object is not a complete function of the user, since it uses only global variables and there is no declared parameter list on which the function value depends.
Maple will not understand the call to the variable F0 as a function in the form F0 (0.1). You must specify the following: t = 0.1: F0:, which is not always convenient.
In the second and third way, the variables listed in the list of formal parameters are local.
For these methods, access to functions occurs in the standard way: the name ( a, b, ...), where a, b, ... are the specific values of the variables.
Inappropriate assignment: = create a user's function as follows: Fn (x): = (x ^ 3:
Although Maple2016 allows you to do this. Fn (2) = 8.
2. User procedures
Procedure (function) - a set of ads and operators designed to perform a separate logical-designed task.
Procedures are an important element of structural programming and serve as a means of expanding the capabilities of the system Maple by the user.
The procedure for Maple -Mo looks like this:
name: = proc (formal parameters)
expression from formal parameters
end proc
Using the function, related concepts: ad, call and definition.
The ad specifies the name of the function, the type returned by the function, the attributes of its formal parameters.
The formal parameters of a function are variables that take values when a function is called in the sequence of their description of the parameter list.
The formal parameters identifiers should not coincide with the identifiers of the variables declared in the middle of the function body (the local operator).
With the operator:: after the formal parameter, you can specify its type.
For example, in proc (n :: Integer), the n variable is an integer.
The discrepancy between the actual parameters of the type of the specified variables results in an error message and a failure to execute the procedure.
To assign the result of the function of various values and exit from it anywhere, use the return(val) statement.
Procedures may not return any values after their execution.
The body of a function is a composite operator.
In Maple, the variables declared in the function body are local.
The management returns to the call location.
General Procedure:
name: = proc (parameters)
local val1, ..., valn;
if bool1 then RETURN (res1) else expr1; expr2; ... ERROR (`error of procedure`); exprn; fi;
res2;
end;
The function call transfers control and the actual arguments (if any) of a given function.
When performing a function call, the actual arguments are assigned to the corresponding formal arguments.
The transfer of control is passed to the first operator of the body of the function.
Returns the default value of the last operator from the body of the function.
The call is performed by name.
An example, a procedure with the name f , which calculates the sum of the variables x and y :
F: = proc (x, y)
x + y;
end;
Actual arguments can be any values.
The called function works with copies of actual arguments, so no change in the values of formal arguments will affect the change in actual arguments.
The library is being built *. lib functions.
Sum of squares of coordinates
save Sqr, Sqrt "D: \\ ParticleSurf \\ BaseGeom.lib";
Include library in program code.
3. Expansion Packages
Some of Maple's functions may be in the standard library and in expansion packets that are part of the basic system supply.
A package is a set of commands for solving tasks relating to certain sections of mathematics.
For example, in the stats package, teams are collected for statistical processing of results, etc.
Before using package features, you need to download them separately or as a whole package.
The list of expansion packets can be obtained using the command:
? index [package]
You can obtain information about an extension package and find a list of functions included in it by using the command:
? name_package
To access the functions of a package, it uses its full boot command:
with (package)
After connecting the packet, the user can call all his commands, simply by typing their name and necessary to execute the parameters directly in the input area.
If you need some specific package features, then instead of connecting the entire package you can only connect these necessary functions:
with (package, f1, f2, ...)
or
with (package, [f1, f2, ...])
Also, the command can be downloaded only at the time of its execution, after which it will be unloaded from memory. To do this, specify its full name, consisting of the package name and the name of the command itself:
Package name [team name] (...);
I / O
For interactive line input there is a readline () function.
To save the results to a disk, you must execute the command: writeto (` name. Ext`).
To read numeric information from a file, use the command: readdata ( name, options, posint) - where name - file name, options - type of variables ( integer / float ), posint - number counter (that is, how many read the numbers from a string).
Readed information is presented as a variable type list. For example, let's in a text file a. txt in the line are numbers: 1 2 3 4 5 6 7 8 9.
The given sequence of commands reads this information from a file in the variable u , after which the sum of the data of numbers is calculated.
Date: = readdata (`a.txt`, integer, 9);
u: = [[1,2,3,4,5,6,7,8,9]]
Sum (date [1] [k], k = 1..9);
4. Graphics library
The Maple core embedded two graphics functions - the construction of two-dimensional graphs ( 2 D- type) - plot () and the construction of three-dimensional graphs ( 3 D- type) - plot3 d ().
Charts are constructed in the form of a number of points, which are joined by straight lines.
The plot operator options
The simplest forms of the plot () function are:
- plot ( f, xmin .. xmax) - construction of the graph of the function f given by the name only;
- plot ( f ( x), x = xmin .. xmax) - construction of the graph of the function f ( x) .
The main parameters of the plot command are :
- title = "text" , where text is the caption of the graph.
- coords = polar - setting of polar coordinates (by default, Cartesian). Other variants: bipolar, cardioid, cassinian, elliptic, hyperbolic, invcassinian, invelliptic, logarithmic, logcosh, maxwell, parabolic, polar, rose, tangent.
- axes - setting the type of coordinate axes: axes = NORMAL - normal axis; axes = BOXED - Schedule in frame with scale; axes = FRAME - centered axis in the lower left corner of the drawing; axes = NONE - without axes.
- scaling - scale setting: scaling = CONSTRAINED - the same scale on the axes; scaling = UNCONSTRAINED - the graph is scaled by the size of the window.
- style = LINE - build lines, style = POINT dot construction.
- numpoints = n is the number of computed graph points (by default n = 50 ).
- Сolor - setting the color of the line: for example, yellow - yellow, etc. Other options: aquamarine black blue navy coral cyan brown gold green gray gray khaki magenta maroon orange pink plum red sienna tan turquoise violet wheat white yellow.
- thickness = n , where n = 1,2,3 ... - the thickness of the line (by default n = 1 ).
- linestyle = n - line type: solid, dotted, etc. (default n = 1 is solid).
- symbol = s - type of character denoted by the points: BOX, CROSS, CIRCLE, POINT .
- font = [ f, style, size] - Set the font type to output text: f specifies the font name: TIMES, COURIER, HELVETICA, SYMBOL ; style specifies the font style: BOLD, ITALIC, UNDERLINE ; size - font size in pt .
- labels = [ tx , ty ] - on inscriptions axes: tx - along axis O x and ty - on the axis O y .
An example of constructing two graphs simultaneously:
plot ([x, x ^ 2], x = -1 .. 3, thickness = [1, 3], color = [red, green]) ;
You can use the smartplot (f) function to quickly plot the graph.
Most graphical functions are represented by the package of plots and plottools, which are called with the command with.
Package plots
The package includes the following functions: [animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, densityplot, display, dualaxisplot, fieldplot, fieldplot3d, gradplot, gradplot3d, implicitplot, implicitplot3d , intersectplot, listcontplot, listcontplot3d, listdensityplot, listplot, listplot3d, loglogplot, logplot, matrixplot, multiple, odeplot, pareto, plotcompare, pointplot, pointplot3d, polarplot, polygonplot, polygonplot3d, polyhedra_supported, polyhedraplot, rootlocus, semilogplot , setcolors, setoptions, setoptions3d, shadebetween, spacecurve, sparsematrixplot, surfdate, textplot, textplot3d, tubeplot animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, densityplot, display, dualaxisplot, fieldplot, fieldplot3d, gradplot, gradplot3d, implicitplot, implicitplot3d, inequal, interactive, interactiveparams, intersectplot, listcontplot, listcontplot3d, listdensityplot, listplot, listplot3d, loglogplot, logplot, matrixplot, multiple, odeplot, pareto, plotcompare, pointplot, pointplot3d, polarplot, polygonplot, polygonplot3d, polyhedra_supported, polyhedraplot, rootlocus, semilogplot, setcolors, setoptions, setoptions3d, shadebetween, spacecurve, sparsematrixplot, surfdata, textplot, textplot3d, tubeplot] .
In addition to the schedules of the plot plots and plottools, here are the packages:
- stats [ statplots ] - construction of graphic statistics;
- Student - a set of graphic operators for general sections of mathematics;
- geometry - construction of objects of geometry of Euclidean on a plane.
- geom3d - construction of Euclidean geometry objects in space.
5. Self-checking
- Which function defines the root square - sqrt, sqr, sign, sin?
- What are the differences between the formal and actual parameters of the function?
- What is the procedure for a user's function differently?
- Name the Maple Library.
- Which team does the specified libraries connect to?
- Name the coordinate system on the plane.
Font Face
Font Size
Text Colour
Background Colour
Font Kerning
Image Visibility
Letter Spacing
Line Height
Link Highlight