This is one of the course material that I made for a Matlab introduction class - 1st class

Attribution Non-Commercial (BY-NC)

9 views

This is one of the course material that I made for a Matlab introduction class - 1st class

Attribution Non-Commercial (BY-NC)

- Midterm 2009
- Matlab r / r Reference
- TCS Placement Papers
- Matrix
- Urnas de Polya y Familia, Las Pastillas de Los...
- Advanced Scientific Computing in Basic With Applications in Chemistry, Biology and Pharmacology
- Pose 25 Lines
- Schultz Article
- c++ program
- MATLAB Notes_PWR.pdf
- Matlab Tut
- Matlab 2008 Record
- Basic Numerical Method Using Scilab-ID2069
- Zeros and Poles of Matrix Transfer Functions and Their Dynamical Interpretation
- DSP-Lab-1
- 20.Computer Science
- SampleExam16s2
- 1512724342Module 14 Typesofmatrices1(2
- NOTES FOR CHEMICAL ENGINEERING MATHS
- Matrices

You are on page 1of 66

Work

space

Current window

directo Prompt: means the

ry Matlab is ready to

window accept command

following the

prompt. Command

history

window

Command window :

Enter the Matlab statements after the

prompt “>>”

Undocking of windows

the command window will be

released from the group of

window.

Control of the

appearance

turned off.

Another appearance of the Matlab

window

•If start the Matlab with command option “-nojvm ” (means: no java virtual

machine)

Advantage:

üThe Matlab starts at a faster speed.

üThe Matlab consumes less memory.

“exit” or “quit” or click on the

X at the upper right corner of

the Matlab window.

Some useful commands

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.

•pwd/cd •help/helpwin/helpdesk/doc

•dir/mkdir/rmdir •lookfor

•delete/copyfile •dbtype

•who/whos •demo

•what/which

•clear/clc

in the following slides. Consult with the online help for more

detail. For example:

>>help who

Useful command –

‘pwd’/’cd’

lpwd (present working directory): the directory of the folder in which

the user is.

lcd ‘ new directory’ : change the working directory to the new directory

specified.

üThe string representing the new directory is enclosed inside

the ‘’ sign

Useful command – ‘dir’,

’mkdir’/‘rmdir’

lCommand ‘dir’ is used to show the files under the specified

folder

lCommand ‘mkdir’ is used to create a new folder.

lCommand ‘rmdir’ is used to delete an empty folder.

Useful command –

‘delete’/’copyfile’

lCommand ‘delete’ is used to delete a file.

lCommand ‘copyfile’ is used to copy file.

Useful command –

‘who’/’whos’

l‘wh/whos: check the variables existed in the memory.

Variables may

also be observed

here.

memory

Useful command – ‘what’

lwhat: find the Matlab source code files exist in the folder

specified.

Useful command –

lwhich:

‘which’

find the full directory of the specified file.

Useful command –

‘clear’/’clc’

lCommand ‘clear’ is used to clear variable from the workspace (memory).

lCommand ‘clc’ is to clean the work space.

information, and there are variables

existed in the workspace memory. Clean command window

Useful command –

‘clear’/’clc’

lCommand ‘clear’ is used to clear variable from the workspace (memory).

lCommand ‘clc’ is to clean the work space.

>> clear

a

Variable “a” is

gone.

>> clear

all

gone.

Useful command – ‘help’

lFor the command “help” alone, the Matlab will display all the

toolboxes that is available from the current system.

Useful command – ‘help’

lhelp + ‘toolbox name’: Matlab displays all the fuction calls available

in the specified boolbox.

Useful command – ‘help’

lhelp + ‘command/function name’: Matlab will display a brief

introduction of the command/function designated.

Useful command –

‘helpwin’

lCommand “helpwin” will open the online help window.

Useful command –

‘helpdesk’

lCommand “helpwin”, “helpdesk” and “doc” will open the online help

window.

Useful command – ‘doc’

lCommand “helpwin” will open the online help window.

Useful command –

‘lookfor’

llookfor + ‘keyword’: Matlab will display all the command/function that

is possible relevant to the keyword.

commands/functions that is

relevant to the keyword

designated.

Useful command –

‘dbtype’

ldbtype + ‘function name’: Matlab will provide the source code of the

function. This command does not work for the “built - in” functions

of Matlab.

Useful command –

‘dbtype’

Source code of

the command

“polar”

Useful command –

‘demo’

lCommand “demo” will open the demonstration window, from where the

user may find help on topics in animation.

Adding path to Matlab

Whenever Matlab receives a command, it checks in the

following order whether the command is:

•A variable

•A built-in function

•A 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 folders,

where 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.

Adding path to Matlab

Use command “path” to view the path of the folders

Adding path to Matlab

To add path to Matlab for source file search, the

user may:

•Use command “ path(path, ‘path to append’) ”

Adding path to Matlab

To add path to Matlab for source file search, the

user may change from the file menu:

•File Set Path

Types of commonly used data and

their derivatives

lCommonly used type of data

ØReal numbers: pi, 1.0, sqrt(2), …

uComplex numbers: 4+i, 5+3i,

ØCharacter / string: ‘YZU’, ‘a’

lEach data is stored as a matrix in Matlab.

dimension allowed in Matlab is 7 , a vector is a matrix with

either one row or one column.

lThere are other type of data objects, such as ‘structure’ and

‘cell’, which we will consider later this semester.

Elementary Mathematical

operations

name for the result of a

statement, Matlab stores the

result with variable “ans”.

followed by clicking the “enter” button.

•To turn off the display of statement result, add

a semicolon ‘;’ at end of the statement.

Elementary Mathematical

operations

lExample s of built-in constants:

Øpi

Øi or j

−1

lCommonly used elementary mathematic functions may be found with

command:

help elfun

Example: “sin”, “cos”, “tan”, “sind”, “cosd”, “tand’” and “exp”

Elementary Mathematical

operations

•Try the other trigonometric functions – for variable in both

radian and degree unit.

•Question: What causes the following “inaccuracy” and how to

correct it?

Elementary Mathematical

operations

•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.

Variables

To keep the result of a statement for later use, the

user may assign a name to the result variable.

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”.

Variables

Matlab is case sensitive, therefore “a” is different from “A”.

Variables

Variable ‘cSine_1’ has been removed from

memory

declaration, each real variable is stored as “double” data type and

occupies 8 bytes.

Variables

Long statement may be continued with more lines append

“…” at end of each line to continue the command .

“…”.

function calls programmed by the users.

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

of data

ØData of different type could be stored under a

variable name structure. (will cover this

later)

Construction of a vector

The elements may be separated with either a comma ‘ , ’ or a

space.

Construction of

vector

Construction of a vector

lConstruct a vector with command

“linspace”:

linspace(init, end, number of point)

Operation on vector

elements

>> 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

>> t(3) = 2 % change the value of the 3rd element 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 2 to

be 6, and a ‘0’ has been % padded to be the 5th

element.

t =

3 7 2 5 0 10

Operation on vector

elements

>> t(4) = [] % delete the 4th element of the vector length of

the vector has % been decreased to be 5

t =

3 7 2 0 10

find the length (total

number of element) of

vector t.

Operation on vector

ØFind the minimum, maximum, sum, mean of a

vector

(may apply to matrix as well)

Operation on vector

ØSort element of vector (may apply to matrix

as well)

Operation on vector

ØProduct of vectors – element by element

product

operators product “*” and power

“ ^ ” indicate the operation is element-

by-element

Operation on vector – the

dot product

ØThe product of a row vector and a column

vector

Operation on vector – the outer

product

ØThe product of a column vector and a row

vector

Construction of special

vectors

lVector with elements of value ‘0’

or ‘1’:

Construction of matrix

lIn matrix construction, different rows are separated with a

semi-colon ‘ ; ’.

lElements in a row are separated with either a space or a comma “

, “.

with command ‘eye(n)’ where

n is the rank of the

matrix.

Property of matrix

lMatlab stores elements in column-wise style

mat2(2,4) = mat2(14)

Operation on matrix – change value of

elements

ØChange value of elements in the matrix – assign value

directly or by operation on elements

element with operation between

columns

Operation on matrix

ØConstruction of a matrix from an existing matrix

ØErase any number of row or column of a matrix

mat1

rows

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

rows or columns

Exchange of the

1st and the 4th

rows

Operation on matrix – information of

matrix

Øsize: find out the dimension of the matrix

Øndims: number of dimension (rank) of the matrix

rank of mat2 is 2 (2

indices)

Operation on matrix –

transpose

ØTranspose of a matrix:

üAdd the apostrophe symbol “ ‘ “ after

the matrix

üUse command ‘transpose’

Operation on matrix –

transpose

Complex conjugate has

been applied upon the

elements

original value

been applied upon the

elements

‘transpose ’

Operation on matrix –

product

ØProduct of matrices

Element-by-element product

Operation on matrix –

inverse

ØCommand “inv” calculates the inverse of

matrices

Operation on matrix – diagonal

elements

ØCommand “diag” extracts the diagonal elements of

matrices

Operation on matrix – eigenvalue

and characteristic polynomial

ØCommand “eig ( A ) ” calculates the eigenvalues of matrix A

ØCommand “round(poly(A))” returns the characteristic polynomial of

matrix A

Eigenvalues of matrix A

are the roots of the

characteristic polynomial

of matrix A

Operation on matrix – display of

characteristic polynomial

ØDisplay the characteristic polynomial with

variable ‘s’

- Midterm 2009Uploaded byRabiah
- Matlab r / r ReferenceUploaded bymohamed ahmed
- TCS Placement PapersUploaded byPrakash Rajendran
- MatrixUploaded byAtul Galande
- Urnas de Polya y Familia, Las Pastillas de Los...Uploaded byCristina Camba Fontevedra
- Advanced Scientific Computing in Basic With Applications in Chemistry, Biology and PharmacologyUploaded byababakhanov
- Pose 25 LinesUploaded byLeiser Hartbeck
- Schultz ArticleUploaded byTara Perea
- c++ programUploaded byGurinder Pal Singh
- MATLAB Notes_PWR.pdfUploaded bymohamed maher
- Matlab TutUploaded bymohamed ahmed
- Matlab 2008 RecordUploaded bysonirocks
- Basic Numerical Method Using Scilab-ID2069Uploaded byRaul Ocola
- Zeros and Poles of Matrix Transfer Functions and Their Dynamical InterpretationUploaded byAnonymous Tph9x741
- DSP-Lab-1Uploaded bymsbhima
- 20.Computer ScienceUploaded byyugavarman
- SampleExam16s2Uploaded byElijah Mercado
- 1512724342Module 14 Typesofmatrices1(2Uploaded byVishal Sharma
- NOTES FOR CHEMICAL ENGINEERING MATHSUploaded byAbhimanyu Dubey
- MatricesUploaded byAbhishekJain
- 07 State Feedback ControlUploaded byPablo
- C++ AssignmentUploaded bySourav Roy
- diseño2Uploaded byMaciel Ramirez
- 99 Ashrae DecoupledUploaded byLTE002
- MatrixUploaded byDaniel Istrate
- A Dsb Tender Clarifications 2Uploaded byanupamkhanna
- matlabUploaded bylucas
- Appl.Phys.Lett_73_3330(1998)Uploaded byCarlos Humberto Costa
- Chapter 6Uploaded bytemkimleang
- TUTORIALS1_5.PDFUploaded byteknikpembakaran2013

- man_8050_oem.pdfUploaded byPaun Al
- V-VLDI-MC006-EUploaded byEng-Mohammed Salem
- Mirage ImplementationUploaded byazrina_nina
- 1ft Antenna (HTT81.202-08)Uploaded byguns1976
- ASE 15.7 ESD 2 Reference Manual Building Blocks Sybase IncUploaded byfracebpe
- Integration of Seismic Inversion Pore PrUploaded bynewmetro
- Soal Diagram FasaUploaded byDecy Putri Efhana
- MPeschel-VLF Cable TestingUploaded byNesarkiran Bagade
- Chow & Tan [Design & Construction of Bored Pile Foundation - 2003]Uploaded byDonny B Tampubolon
- Semiconductor Devices Module 1 NotesUploaded byAssini Hussain
- Sizing of Water Piping System.pdfUploaded byorganicspolybond
- me_web_module.pdfUploaded byAnvit Tiwari
- UNIT IIIUploaded byAshwin Parakkal
- CT5123_LectureNotesThe Finite Element Method an IntroductionUploaded byXristoforos Kolomvos
- Eurocode 6 PDFUploaded byTerrance
- AdityaUploaded byUtkarsh Choudhary
- 2130114 MC Hardware Integration Guide v3Uploaded byVlacho Matiz
- Bolt Calculation Method AgatonovicAdvancBalkenModelUploaded byjvalverdegarcia
- 06361-HSBZ-CA-22353-1.-0019 & Coal Bunker Frame Beam Connection to Column WebUploaded byVasanthakumar
- y -CUP (2009)Uploaded byPepe Luis
- SJL AppNote 009 - Ciphering and Secure RRC DecodingUploaded byRandy Chung
- Honeywell 5808w3 Install GuideUploaded byAlarm Grid Home Security and Alarm Monitoring
- 1056(1)Uploaded byDaniel Orbes Padilla
- Getting Started TIMES-VEDA V2p7Uploaded byKudaibergenov Assylbek
- Solar Based Induction Cook Top.pdfUploaded byvajirashish
- SagarBodkhe Resume Final MEfinalyear ME10055Uploaded bySagar Bodkhe
- Memory LeakUploaded bydefuser
- Research MethodologyUploaded byJohny
- Border Gateway Protocol (BGP): A Simulation Based OverviewUploaded byAnonymous vQrJlEN
- Accessing the Amazon Elastic Compute Cloud 2012-04-24Uploaded bySH MI LY