- •Міністерство освіти і науки, молоді та спорту україни
- •Laboratory Works of Computing and Programming
- •Contents
- •1.2 Base Concepts of Operating Systems
- •1.3 Linux (lubuntu) Operating System
- •1.4 Tasks for Independent Work
- •1.5 Test Questions
- •2 Laboratory work № 2 Word Processor libreoffice.Writer
- •2.1 What Word Processors Can Do
- •2.2 Tasks for Independent Work
- •2.3 Test Questions
- •3 Laboratory work № 3
- •Introduction to the calc spreadsheet
- •3.1 The Basic Opportunities of Spreadsheets
- •3.1.1 Calc’s Environment
- •3.1.2 Calculations in Calc. Creating and Coping Formulas
- •3.2 The Calc charting capability
- •3.3 Tasks for Independent Work
- •4.2 Main Rules of Works in Scilab System
- •Variables
- •Input of vectors (arrays)
- •Input of matrixes
- •Some operations with matrixes with use of the operator ":"
- •Input from keyboard
- •Operators. Expressions use familiar arithmetic operators and precedence rules.
- •Intrinsic scilab Functions
- •Examples of Expressions
- •4.3 Individual Tasks for Laboratory Work
- •4.4 The Tasks for Self-Examination
- •4.5 Test Questions
- •5 Laboratory work № 5
- •5.3.1The plot function
- •5.3.3 Preparing Graphs for Presentation
- •Interactive Plot Editing
- •5.3.4 3D Plotting
- •5.4 Individual Tasks
- •5.6 Test Questions
- •6 Laboratory work № 6 programming in Scilab
- •6.1 Programming in scilab
- •What Happens When You Call a Function
- •Clearing Functions from Memory
- •6.2 Tasks for laboratory work
- •6.3 Example of performance of the laboratory work
- •6.4 Test Questions
- •7 ReferencEs
Interactive Plot Editing
If you enable plot editing mode in the SCILAB figure window, you can perform point-and-click editing of the objects in your graph. In this mode, you select the object or objects you want to edit by double-clicking it. This starts the Property Editor, which provides access to properties of the object that control its appearance and behavior.
Plot editing mode provides an alternative way to access the properties of SCILAB graphic objects. However, you can only access a subset of object properties through this mechanism. You may need to use a combination of interactive editing and command line editing to achieve the effect you desire.
Printing Graphics
You can print a SCILAB figure directly on a printer connected to your computer or you can export the figure to one of the standard graphic file formats supported by SCILAB. There are two ways to print and export figures:
using the Print option under the File menu
using the print command
Printing from the Menu
There are four menu options under the File menu that pertain to printing:
the Page Setup option displays a dialog box that enables you to adjust characteristics of the figure on the printed page.
the Print Setup option displays a dialog box that sets printing defaults, but does not actually print the figure.
the Print Preview option enables you to view the figure the way it will look on the printed page.
the Print option displays a dialog box that lets you select standard printing options and print the figure.
Generally, use Print Preview to determine whether the printed output is what you want. If not, use the Page Setup dialog box to change the output settings. Select the Page Setup dialog box Help button to display information on how to set up the page.
Exporting Figure to Graphics Files
The Export option under the File menu enables you to export the figure to a variety of standard graphics file formats.
5.3.4 3D Plotting
Scilab provides many powerful instructions for the visualization of 3D data. The instructions provided include tools to plot wire-frame objects, 3D plots, curves, surfaces, and can automatically generate contours, display volumetric data, interpolate shading colors. Here are some commonly used functions (there are many more):
plot3, stem3, pie3, comet3, contour3, mesh, meshc,
surf, surfc, sphere, ellipsoid, cylinder.
Among these instructions, plot3 and comet3 are the 3D matches of plot and comet commands mentioned in the 2D plot section.
The 3D plot functions intended for plotting meshes and surfaces 'mesh' and 'surf', and their several variants 'meshc', 'meshz', 'surfc', and 'surfl', take multiple optional input arguments, the most simple form being 'mesh(z)' or 'surf(z)', where z represents a matrix.
Usually, tridimensional curves are represented by the values of z-coordinates samples on a grid of (x,y) values.
Thus, to create a surface or 3D plot we first need to generate a grid of (x,y) coordinates and find the height (z-coordinate) of the surface at each of the grid points. Scilab provides the function 'meshgrid' to create a grid of points over a specified range.
Meshgrid
Suppose that you want to plot the function z = x2 – 10y + 2 over the domain 0 ≤ x ≤ 4 and 0 ≤ y ≤ 4. To do so, we first take several points in the domain, say 25 points, as shown in fig.5.6:
Figure 5.6 - Grid to calculate the function
We can create two matrices x and y, each of size 5 x 5, and write the xy-coordinates of each point in these matrices. We can then evaluate z with the command z = x.^2 – 10*y + 2.
However, creating the two matrices x and y is much easier with the meshgrid command.
>>vx = 0 : 4 % creates vectors x and y, from 0 to 4
vx = 0 1 2 3 4
>>vy = vx
vy = 0 1 2 3 4
>>[x,y] = meshgrid(vx,vy) % creates meshgrid to be used in 3D plot
x = 0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
0 1 2 3 4
y = 0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
The commands shown above generate the 25 points shown in the figure. All we need to do is generate two vectors, vx and vy, to define the region of interest and distribution or density of our grid points. Also, this two vectors do not have to be either the same size or linearly spaced. It is very important to understand the use of meshgrid.
See the columns of x and the rows of y. When a surface is plotted with the 'mesh(z)' command (where z is a matrix), the tickmarks on the x and y axes do not indicate the domain of z but the row and column indices of the z-matrix. Typing 'mesh(x,y,z)' or 'surf(x,y,z)' (where x and y are vectors used by 'meshgrid' to create a grid), result in the surface plot of z, with x and y values shown along the respective axes.
Surf and Surfc
surf(X,Y,Z) creates a shaded surface using Z for the color data as well as surface height. X and Y are vectors or matrices defining the X and Y components of a surface. If X and Y are vectors, length(X) = n and length(Y) = m, where [m,n] = size(Z). In this case, the vertices of the surface faces are (X(j), Y(i), Z(i,j)) triples. To create X and Y matrices for arbitrary domains, use the meshgrid function.
surfc(...) draws a contour plot beneath the surface.
Example 5.1. We'll 3D plot the following surface:
Type following commands:
>> vx = -4 : 0.2: 4;
>> vy = -3 : 0.2: 3;
>> [x,y] = meshgrid(vx, vy); % calculates the necessary grid
>> z = x .* y .* (x.^2 - y.^2) ./ (x.^2 + y.^2 + eps); % calculates z
>> surfc(x,y,z)
Figure 5.7 – Surface for example 5.1