20100310-17
TRANSCRIPT
-
8/9/2019 20100310-17
1/66
:ommand windownter the Matlab statements after the>>rompt
ommandistorywindow
ork pacewindowurrentdirectoywindow
Appearance of the Matlab mainwindow
View or change the current working directory
:Prompt means theMatlab is ready to
accept commandfollowing the
.prompt
-
8/9/2019 20100310-17
2/66
Undocking of windows
,Click the undock button andthe command window will be
released from the group of.window
-
8/9/2019 20100310-17
3/66
Control of theappearance
Uncheck the option and the corresponding window will be
.turned off
-
8/9/2019 20100310-17
4/66
If start the Matlab with command option -nojvm ( :means no java virtual)machine
Another appearance of the Matlabwindow
Advantage : .The Matlab starts at a faster speed .The Matlab consumes less memory
,To leave Matlab either enter exit or quit or click on theX at the upper right corner of
.the Matlab window
-
8/9/2019 20100310-17
5/66
Some useful commands
/pwd cd
/ /dir mkdir rmdir /delete copyfile /who whos /what which /clear clc
MATLAB is -case sensitive - it differentiates between the.lowercase and uppercase letters Thus 'm' and 'M' are different
. -variables The built in commands and function in MATLAB are.typed in lowercase letters
/ / /help helpwin helpdesk doc
lookfordbtypedemo
Only the most fundamental usage of the commands will be presented.in the following slides Consult with the online help for more
. :detail For example
>>help who
-
8/9/2019 20100310-17
6/66
Useful command pwd/cd
l (pwd p resent w orking d ):irectory the directory of the folder in which.the user is
l cd new directory : change the working directory to the new directory.specified
The string representing the new directory is enclosed inside
the sign
-
8/9/2019 20100310-17
7/66
Useful command dir,mkdir/rmdirl Command dir is used to show the files under the specified
folderl .Command mkdir is used to create a new folderl Command rmdir is used to delete an empty .folder
-
8/9/2019 20100310-17
8/66
Useful command delete/copyfile
l .Command delete is used to delete a filel .Command copyfile is used to copy file
-
8/9/2019 20100310-17
9/66
Useful command who/whos
l / : .wh whos check the variables existed in the memory
Each variable is stored as a matrix in thememory
Variables mayalso be observed
.here
-
8/9/2019 20100310-17
10/66
Useful command what
l :what find the Matlab source code files exist in the folder.specified
Find source files in the specified directory
,By default the current folder
-
8/9/2019 20100310-17
11/66
Useful command which
l : .which find the full directory of the specified file
-
8/9/2019 20100310-17
12/66
-
8/9/2019 20100310-17
13/66
Useful command clear/clc
l ( ).Command clear is used to clear variable from the workspace memoryl .Command clc is to clean the work space
Variable a is.gone
All the variable are
.gone
>> leara
>> learall
-
8/9/2019 20100310-17
14/66
Useful command help
l ,For the command help alone the Matlab will display all the.toolboxes that is available from the current system
-
8/9/2019 20100310-17
15/66
Useful command help
l + :help toolbox name Matlab displays all the fuction calls available.in the specified boolbox
-
8/9/2019 20100310-17
16/66
Useful command help
l + / :help command function name Matlab will display a brief/ .introduction of the command function designated
-
8/9/2019 20100310-17
17/66
Useful command helpwin
l .Command helpwin will open the online help window
-
8/9/2019 20100310-17
18/66
Useful command helpdesk
l , Command helpwin helpdesk and doc will open the online help.window
-
8/9/2019 20100310-17
19/66
Useful command doc
l .Command helpwin will open the online help window
-
8/9/2019 20100310-17
20/66
Useful command lookfor
l + : /lookfor keyword Matlab will display all the command function that
.is possible relevant to the keyword
Matlab shows all the/commands functions that isrelevant to the keyword
.designated
f l d
-
8/9/2019 20100310-17
21/66
Useful command dbtype
l + :dbtype function name Matlab will provide the source code of the
.function This command does not work for the -uilt in functions.of Matlab
f l d
-
8/9/2019 20100310-17
22/66
Useful command dbtype
Source code ofthe command polar
f l d
-
8/9/2019 20100310-17
23/66
Useful command demo
l ,Command demo will open the demonstration window from where the
.user may find help on topics in animation
-
8/9/2019 20100310-17
24/66
Adding path to Matlab
, Whenever Matlab receives a command it checks in the:following order whether the command isA variable -A built in functionA Matlab source code filename in the current folder
A Matlab source code filename in other folders .listed in the environment variable path
,The user may want to add directory of more folderswhere there are Matlab source code file generated
,by the user to the Matlab environment variable path such that the Matlab has access to the.source code files in those folders for later use
-
8/9/2019 20100310-17
25/66
Adding path to Matlab
Use command path to view the path of the folders
-
8/9/2019 20100310-17
26/66
Adding path to Matlab
,To add path to Matlab for source file search the:user may ( , ) Use command path path path to append
-
8/9/2019 20100310-17
27/66
Adding path to Matlab
,To add path to Matlab for source file search the:user may change from the file menuFile Set Path
-
8/9/2019 20100310-17
28/66
-
8/9/2019 20100310-17
29/66
Types of commonly used data andtheir derivatives
lCommonly used type of data : , . , ( ), Real numbers pi 1 0 sqrt 2
u : + , + ,Complex numbers 4 i 5 3i / : , Character string YZU a
l .Each data is stored as a matrix in Matlab
l A /rray matrix ,is a group of the same type data the maximumdimension allowed in Matlab is 7 , a vector is a matrix with
.either one row or one columnl , There are other type of data objects such as structure and
, .cell which we will consider later this semester
-
8/9/2019 20100310-17
30/66
Elementary Mathematicaloperations
>>,Enter the statements next to the prompt .followed by clicking the enter button
,To turn off the display of statement result adda semicolon ; .at end of the statement
Without assigning any variablename for the result of a
,statement Matlab stores the
.result with variable ans
-
8/9/2019 20100310-17
31/66
Elementary Mathematicaloperationsl - :Example s of built in constantspi i o r j
l Commonly used elementary mathematic functions may be found with:command
help elfun
: , , , , , Example sin cos tan sind cosd tand and exp
1
-
8/9/2019 20100310-17
32/66
Elementary Mathematicaloperations
Try the other trigonometric functions for variable in both
.radian and degree unitQuestion : What causes the following inaccuracy and how to
correct it?
-
8/9/2019 20100310-17
33/66
Elementary Mathematicaloperations
-May put more than one statements in a line use comma or semi
.colon to separate the statements Matlab echoes the result of a,statement that ends with a comma but not for a statement that.ends with a semicolon
.Space between statements does not change the statements
-
8/9/2019 20100310-17
34/66
Variables
:Rules for variable naming / ,Name of a variable must begin with a character letter say
, , , , ,a b a17 E_in My_var and the maximum length of variable
name is 31 .characters For variable with name longer than,31 characters Matlab keeps the first 31 figures and ignore.the rest
:Acceptable ingredients for the variable name are/ , , .character letters numbers _
: .Variable name is case sensitive a is different from A
.No need to declare the data type of variable ,No space is allowed at middle of any variable name such
: .as is number Variables could be cleared by using command clear
.variable name
,To keep the result of a statement for later use the.user may assign a name to the result variable
-
8/9/2019 20100310-17
35/66
Variables, .Matlab is case sensitive therefore a is different from A
.No space is allowable in middle of a variable name
-
8/9/2019 20100310-17
36/66
Variables Variable cSine_1 has been removed from
memory
,Observed from response of command whos without additional
, declaration each real variable is stored as double data type and.occupies 8 bytes
-
8/9/2019 20100310-17
37/66
VariablesLong statement may be continued with more lines append
.at end of each line to continue the command
A space is placed between 7 and.
This technique is commonly used in script files and
.function calls programmed by the users
-
8/9/2019 20100310-17
38/66
-
8/9/2019 20100310-17
39/66
Vector and matrix Vector and matrix are used to store and represent a group
of data of the same . (type A vector is a matrix of either.)one row or one column
Different assemble type
-
8/9/2019 20100310-17
40/66
Different assemble typeof data
Data of different type could be stored under a. (variable name structure will cover this
)later
-
8/9/2019 20100310-17
41/66
Construction of a vector
The elements may be separated with either a comma , or aspace .
Construction ofvector
-
8/9/2019 20100310-17
42/66
Construction of a vectorlConstruct a vector with command
:linspace( , , )linspace init end number of point
Operation on vector
-
8/9/2019 20100310-17
43/66
Operation on vectorelements
>> = [ ];s 1 3 5 2 % use [] for construction of a vector separate the% elements with either a comma , or a space>> = * +t 2 s 1
=t 3 7 11 5
l MATLAB may operate on a ingle element /of the vector matrix >> (t 3) = 2 % change the value of the 3rdelement to 2
=t 3 7 2 5
>> (t 6) = 10 % append one more element to the end of the, %vector length of the vector is increased by 2to
, %be 6 and a 0 has been padded to be the 5th.element
=t 3 7 2 5 0 10
Operation on vector
-
8/9/2019 20100310-17
44/66
Operation on vectorelements
>> ( ) =t 4 [] % delete the 4thelement of the vector length of%the vector has been decreased to be 5
=t 3 7 2 0 10
Use command length to(find the length total)number of element of
.vector t
-
8/9/2019 20100310-17
45/66
Operation on vector , , ,Find the minimum maximum sum mean of a
vector
( )may apply to matrix as well
-
8/9/2019 20100310-17
46/66
Operation on vector (Sort element of vector may apply to matrix
)as well
-
8/9/2019 20100310-17
47/66
Operation on vector
Product of vectors element by elementproduct
The dot symbol . in front of the
operators *roduct and ower -indicate the operation is element-by element
Operation on vector the
-
8/9/2019 20100310-17
48/66
Operation on vector thedot product
The product of a row vector and a columnvector
O ti t th t
-
8/9/2019 20100310-17
49/66
Operation on vector the outerproduct
The product of a column vector and a row
vector
Construction of special
-
8/9/2019 20100310-17
50/66
Construction of specialvectorsl Vector with elements of value 0 :or 1
-
8/9/2019 20100310-17
51/66
-
8/9/2019 20100310-17
52/66
Construction of matrixl ,In matrix construction different rowsare separated with a-
semi colon
; .l Elements in a row are separated with either a space or a comma, .
Identity matrix is created ( )with command eye n wheren is the rank of the
.matrix
-
8/9/2019 20100310-17
53/66
Property of matrixl -Matlab stores elements in column wise style
( , ) = ( )mat2 2 4 mat2 14
Operation on matrix change value of
-
8/9/2019 20100310-17
54/66
Operation on matrix change value ofelements
Change value of elements in the matrix assign value
directly or by operation on elements
.Change value of an element directly
Change value of a column ofelement with operation between
columns
-
8/9/2019 20100310-17
55/66
Operation on matrixConstruction of a matrix from an existing matrix
Erase any number of row or column of a matrix
Erase the 5thand 6th
rows
Construct mat2 from
mat1
-
8/9/2019 20100310-17
56/66
Operation on matrix - flip Command flipud flips the matrix upside down
- -Command fliplf flips the matrix left hand to right
hand
Operation on matrix exchange of
-
8/9/2019 20100310-17
57/66
Operation on matrix exchange ofrows or columns
Exchange of the1stand the 4th
rows
Operation on matrix information of
-
8/9/2019 20100310-17
58/66
Operation on matrix information ofmatrix
:size find out the dimension of the matrix
: ( )ndims number of dimension rank of the matrix
(rank of mat2 is 2 2)indices
mat2 is a 4x4 matrix
Operation on matrix
-
8/9/2019 20100310-17
59/66
Operation on matrix transpose
:Transpose of a matrix
Add the apostrophe symbol afterthe matrix Use command transpose
Operation on matrix
-
8/9/2019 20100310-17
60/66
Operation on matrix transpose
Difference between and command transpose
Complex conjugate hasbeen applied upon the
elements
Complex conjugate hasbeen applied upon the
elements
Elements are kept theoriginal value
Operation on matrix
-
8/9/2019 20100310-17
61/66
Operation on matrix product
Product of matrices
- -Element by element product
Common matrix product
Operation on matrix
-
8/9/2019 20100310-17
62/66
Operation on matrix inverse
Command inv
calculates the inverse of
matrices
Operation on matrix diagonal
-
8/9/2019 20100310-17
63/66
Operation on matrix diagonalelements
Command diag
extracts the diagonal elements of
matrices
Operation on matrix eigenvalue
-
8/9/2019 20100310-17
64/66
Operation on matrix eigenvalueand characteristic polynomial
Command ( )ig A calculates the eigenvalues of matrix A ( ( ))Command round poly A returns the characteristic polynomial of
matrix A
Eigenvalues of matrix Aare the roots of the
characteristic polynomialof matrix A
Operation on matrix display of
-
8/9/2019 20100310-17
65/66
Operation on matrix display ofcharacteristic polynomial
Display the characteristic polynomial with
variable s
-
8/9/2019 20100310-17
66/66