Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Laboratory work 5.1eng.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
3.47 Mб
Скачать

Laboratory work №5.1 (4 hour)

Features of the using MathLab package. Problems of linear algebra, working with functions in the MathLab.

MATLAB has the following basic window components (fig. 5.1.1):

- Menu;

- Panels with the buttons;

- Launch Pad Window - to access all MATLAB services and toolboxes

- Command Window - to execute commands in the MATLAB environment

- Current Directory Window - to quickly access files on the MATLAB path

- Figure Window - to display graphical output from MATLAB code

- Workspace Window - to view variable definitions and variable memory allocations

- M-File Editor/Debugger Window - to write M-files (includes color-coded syntax features) and to debug M-files interactively (break points)

- MATLAB Path Window - to add and delete folders to the MATLAB path

- Command History Window - displays all commands issued in MATLAB since the last session (good for learning and verification)

- Status bars.

Fig. 5.1.1.

Simplest calculations

All commands in this mode take in a command line after the sign of invitation >>. Set ends with pressure of Enter, whereupon MatLab will execute a command or will calculate the entered expression.

For the input of expressions different built in functions are used. Names of built in functions take lowercases, and arguments consist in brackets.

At the input of command help it is possible to know the names of all categories of built in functions of MatLab. Knowing the name of category, it is possible to look over the names of all functions of this theme. For example, command

>>help elmat

the list of all elementary mathematical functions will show, and

>>help general

the list of general purpose functions will show.

It is possible to get also a help on a concrete function, setting, for example, a command

>>help format,

it is possible to know everything about the general purpose function format, which the format of output of result of calculations is set by means of.

Task 1.

Using the command help, will look over, as the names of elementary mathematical functions look.

Task 2.

Enter next expression in a command line:

and press Enter.

At an input use the built-in function for the calculation of exhibitor, natural logarithm, square root and trigonometric functions. For an input p use the system constant pi.

Arithmetic operations are carried out regularly, peculiar to programming languages:

- Exponentiation ^;

- Multiplication and division *,/;

- Addition and subtraction +,-.

For the change of calculations order use brackets.

If the typed expression very long, it can be continued on a next line, for this purpose in the place of breaking it is needed to type three points without blanks, and then to continue expression on a next line.

An answer will hatch in a command window in a kind:

ans =

...-3.2105

"ans" temporal variable which is determined by MatLab, if you did not appoint a variable for maintenance of operation result.

Task 3.

You will get more exact result. For this purpose will execute the command format long e, after that press the key ↑ until the expression typed before will not appear in a command line, after press Enter.

ans =

- 3.210497097863031e+000

Showing out a result in other format is possible without the repeated calculation. For this purpose do the following: will change a format the command short, and then type in a command line the name of variable ans and press Enter.

>> format short

>> ans

ans =

-3.2105

In case if there are exceptional situations at calculations, for example, dividing by a zero, a warning message is produced and calculated variable takes on next values: Inf (endlessness) at dividing of positive number by a zero, - Inf (minus endlessness) at dividing of negative number by a zero, NaN (not number) at dividing of zero by a zero.

Use of variables

MatLab allows to use variables. As an operator of appropriating a sign = is used.

Task 4.

Find the value of next expression

Pay attention to that, as in numerator and in a denominator there are identical expressions. Appropriate this expressions to the variables x and y, and only after that calculate common expression, using the names of variables. In order to the results of intermediate calculations did not hatch on the screen, use a semicolon ";" at the end of command.

Answer

z =

0.0243 - 0.9997i

Working environment saving

For saving it is necessary to choose the point Save Workspace As in the menu File, and to set a path and file name in an appearing dialog box. Expansion of such file will have .mat. The values of all variables, which were used in a session, are saved in a working environment.

In a next session for renewal of values of variables it is necessary to open the stored file, choosing the point Load Workspace in the menu File.

To save and to recover the variables of working environment it is possible by means of corresponding commands (save and load) from a command line.

Task 5.

You will save a Workspace, typing in a command line

>> save work13-10-04

Close MatLab, will start him again, open the stored file, typing in a command line

>> load work13-10-04

You will look over the values of all variables by means of the key ↑. These variables can be used again in the entered commands.

There is possibility to write down executable commands and results in a text file (to journalize work) which can be looked over in a text editor in MatLab. For this purpose a command

>> diary file name_.txt

serves.

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