Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
labScilab_English_Part1.doc
Скачиваний:
26
Добавлен:
07.02.2016
Размер:
2.38 Mб
Скачать

What Happens When You Call a Function

When you call a function from either the command line or from within another program file, SCILAB parses the function into pseudocode and stores it in memory. This prevents SCILAB from having to reparse a function each time you call it during a session. The pseudocode remains in memory until you clear it using the clear function, or until you quit SCILAB.

Clearing Functions from Memory

You can use clear in any of the following ways to remove functions from the SCILAB workspace.

Syntax

Description

clear functionname

Remove specified function from workspace

clear functions

Remove all compiled functions

clear all

Remove all variables and functions

6.2 Tasks for laboratory work

1. Create functions for tasks from laboratory work 3 and call it with different arguments.

2. Create script, which build plots for your task in laboratory work 3.

6.3 Example of performance of the laboratory work

Create functions and write scripts to build plots of functions.

а) - function of one variable;

b) - function y(x) is given parametrically;

c) - function of two variables, surface.

Functions for task:

File f1.m

function y=f1(x)

y=sin(x).*exp(-2*x);

File f2.m

function [x,y]=f2(t)

x=2*cos(t).*sin(4*t);

y=2*sin(4*t).*sin(t);

File f3.m

function [X,Y,Z]=f3(x,y)

[X,Y] = meshgrid(x,y);

Z = X .* exp(-X.^2 - Y.^2);

Scripts for task and results of script work:

File plot_a.m

% script for plots

x=0:0.1:pi; y=f1(x);

plot(x,y,'LineWidth',3)

grid on

The command >> plot_a outputs the plot on fig. 6.1.

Figure 6.1 – plot for task (a)

File plot_b.m

% script for b)

t=0:0.02:2*pi; [x,y]=f2(t);

plot(x,y,'LineWidth',2)

grid on

The command >> plot_b outputs the plot on fig. 6.2.

Figure 6.2 – plot for task (b)

File plot_c.m

% script for surface

x=-2:0.2:2; y=-2:0.2:2;

[X,Y,Z]=f3(x,y);

surf(X,Y,Z)

The command >> plot_c outputs the plot on fig. 6.3.

Figure 6.3 – plot for task (c)

6.4 Test Questions

  1. What kinds of program files can you create in Scilab?

  2. How to create m-file?

  3. What is script?

  4. How to start script file?

  5. What structure has M-function?

  6. How to invoke user function?

  7. What difference between scripts and functions?

  8. What parameters we call dummy parameters?

  9. What parameters are actual?

  10. How actual parameters are passed to function?

7 ReferencEs

  1. Л.М. Дибкова. Інформатика та комп’ютерна техніка. Посібник для студентів. – К.: Видавничий центр “Академія”, 2002. – 592с.

  2. Інформатика. Комп’ютерна техніка. Комп’ютерні технології. Підручник. – К.:Каравела, 2003. – 464 с.

  3. Інформатика: Комп’ютерна техніка. Комп’ютерні технології. Посіб./ За ред. О.І. Пушкаря – К.: Видавничий центр “Академія”, 2001. – 696с.

  4. Ross L. Spencer, INTRODUCTION TO SCILAB. Department of Physics and Astronomy, Brigham Young University, 2000.

  5. Дьяконов В. П. SCILAB 7.*/R2006/R2007: Самоучитель. – М.: ДМК Пресс, 2008. – 768 с.: ил.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]