Основы Системы MATLAB Basic MATLAB Programming MATLAB Cистема


Основы Системы MATLAB Basic MATLAB Programming

MATLAB Cистема MatLab (Matrix Laboratory) является интерактивной системой для выполнения инженерных и научных расчетов, ориентированная на работу с массивами данных в программном и интерактивном режиме с векторами и матрицами. Она позволяет решать системы уравнений, строить графики и др.

What we will learn in this session History The basic MATLAB interface. Basic commands. Declaring & manipulating variables. Plotting graphs. Conditional Operators. Functions.

История MATLAB History MATLAB MATLAB как язык программирования был разработан Кливом Моулером (англ. Cleve Moler) в конце 1970-х годов, когда он был деканом факультета компьютерных наук в Университете Нью-Мексико.

История MATLAB History MATLAB В 1983 году Инженер Джон Литтл (англ. John N. Little) познакомился с этим языком. Джон, Клив и Стив Бангерт (англ. Steve Bangert). Совместными усилиями они переписали MATLAB на C и основали в 1984 компанию The MathWorks для дальнейшего развития MATLAB.

Основной интерфейс MATLAB Basic MATLAB Interface «Опыт показывает, что студенты, владеющие программированием в разных языках, улавливают технологию программирования и работы в MatLab’е в течение 2-3 часов (с фантастическими возможностями системы можно знакомиться месяцами)»

Основной интерфейс MATLAB Basic MATLAB Interface

Command Window type commands Current Directory View folders and m-files Workspace View program variables Double click on a variable to see it in the Array Editor Command History view past commands save a whole session using diary Основной интерфейс MATLAB Basic MATLAB Interface

Command window: Type your instructions here and press ENTER to execute them. Командное окно: набрать команды или выражения и, нажав ENTER, чтобы выполнять их. Основной интерфейс MATLAB Basic MATLAB Interface Командное окно Command window >>

Example: Declare a column matrix with values 1,2 and 3. Основной интерфейс MATLAB Basic MATLAB Interface Командное окно Command window >>

Command history: a list of instructions executed by MATLAB is shown here. Окно истории команд Command History

Workspace: shows a list of variables created by MATLAB. As you can see, the value of ‘aaa’ is shown. Рабочая область Workspace

Рабочая область Workspace Another way to create a variable Is to press this button.

MATLAB will prompt you to enter the variable name.

As you can see, the variable name has been changed to bbb.

To assign a value to bbb, you can do it in two ways: 1) Using the command window.

When you click on bbb, the variable editor window appears. You can type in new values into bbb by filling in the cells. 2) Or by double clicking on bbb.

An example is shown here. Try and do it yourself.

To display variables at the console, you can type the variable name, or you can type disp(variable_name).

To clear all variables from memory and close all figures, use the clear, close all command.

As you can see, all workspace variables are deleted when you execute this command.

To clear the command window, use the clc (clear console) command.

As you can see, all console entries are deleted when you execute this command.

Example: search for function mean Or you can press F1 to display the help window. Click on Open Help Browser to search for a specific function.

Current Directory: View folders and m-files Основной интерфейс MATLAB Basic MATLAB Interface Текущий каталог Current Directory

Основные команды Basic Commands

Переменные Variables MATLAB can be used to initialize and manipulate many types of variables. Single value. Matrix (Vector) String

Переменных Single Variables Для декларации переменных, введите название переменной и ее значение. Например: var = 3; nameVar = 56; Var = 5 ****!!!! Переменные не могут иметь цифры или символы перед ними. Неправильные примеры: 2var #aaa XXXX “ ; “ No Display Variable on Command Window


Переменные типа матриц Matrix (Vector) Variables Значения переменных типа (векторов) матриц определяются в квадратных скобках. Пример: aaa = [1,2,3,4]; bbb = [1;2;3;4]; cсс = [1,2;3,4]

Матрица-строка (Вектор-cтрока) Row Matrix To create a row matrix, use the comma or Space to separate the values. Example: rowMatrix = [1,2,3,4,5]; RowM = [3 14 1 234]

Матрица-столбец (вектор-столбец) Column Matrix To create a column matrix, use the semicolon or ENTER to separate the values. Example: colMatrix = [1;2;3;4;5]; ColM = [1 2 5]

Матрица Regular Matrix To create a regular matrix, use the comma (space) to separate each value in a row, and a semicolon (ENTER) to enter the value for a new row. Example: mat1 = [1,2,3;4,5,6;7,8,9];

Попробуйте сами Сформировать такие матрицы:

Длинные Матрицы (Векторы) Long Matrix (Vector) t = 1:10 t = 1 2 3 4 5 6 7 8 9 10 k = 2:-0.5:-1 k = 2 1.5 1 0.5 0 -0.5 -1 B = [1:4; 5:8] x = 1 2 3 4 5 6 7 8

Accessing Matrix Values To access a specific value inside a matrix, use this command: matrixName(rowNumber, colNumber) vectorName(Number) Example: to access a value inside row 3 and column 2. matrixName(3,2) EleMatrix = matrixB(2,2) EleVector = k(3)

Accessing Whole Columns and Rows To get a whole column, use this command: varA = matName(:,colNumber); To get a whole row, use this command: varB = matName(rowNumber,:); Examples: varA = matrixB(2,:); varB = matrixB(:,1); VarA = B(:,2:4) VarB = B(1,1:2)

Get all the values from row 3 and save it into a new variable. Get all the values from column 1 and save it into a new variable. Попробуйте сами Сформировать такую матрицу:

Формирование векторов с помощью функций Generating Vectors from functions zeros(M,N) MxN matrix of zeros ones(M,N) MxN matrix of ones rand(M,N) MxN matrix of uniformly distributed random numbers on (0,1) x = zeros(1,3) x = 0 0 0 x = ones(1,3) x = 1 1 1 x = rand(1,3) x = 0.9501 0.2311 0.6068

Формирование матриц с помощью функций Generating Matrix from functions zeros(M) MxM matrix of zeros ones(M) MxM matrix of ones rand(M) MxM matrix of uniformly distributed random numbers on (0,1) x = zeros(3) x = ones(3) x = rand(3)
![Конкатенация матриц (векторов) Concatenation of Matrices Create: x = [1 2], y = Конкатенация матриц (векторов) Concatenation of Matrices Create: x = [1 2], y =](https://present5.com/presentacii-2/20171208\2424-matlab_ruso_1_-_matlab_fundamentals.ppt\2424-matlab_ruso_1_-_matlab_fundamentals_41.jpg)
Конкатенация матриц (векторов) Concatenation of Matrices Create: x = [1 2], y = [4 5], z=[0 0] A = [ x y] 1 2 4 5 B = [x ; y] 1 2 4 5 C = [x y ;z] Error: ??? Error using ==> vertcat CAT arguments dimensions are not consistent.

ЖЖЖЖCreating a Matrix Луис_А_Руис (11 элементов) 13 ,21, 10, 19, 34, 1, 34, 18, 21, 10, 19 Сформировать миним-ю квад-ю матр. личные элементы -- нули (0) Название переменной иниц. ИОФ

ЖЖЖЖCreating a Matrix Напремер: NxN 13 ,21, 10, 19, 34, 1, 34, 18, 21, 10, 19 Из такой матр. получить: Только имя в новой переменной Nam Только фам. в другой переменной Fam Сформировать матр. NxN с столбцами нулей и единиц, чередовано. (ones, zeros)

2424-matlab_ruso_1_-_matlab_fundamentals.ppt
- Количество слайдов: 43