SlideShare a Scribd company logo
Last modified:January 1, 1970 GMT
An Introduction to Matlab(tm): Lesson 1
Some basic commands you will need:
matlab loads the program matlab into your workspace
quit
quits matlab, returning you to the operating system
exit
same as quit
who
lists all of the variables in your matlab workspace
whos
list the variables and describes their matrix size
NOTE - When using the workstations, clicking on UP ARROW will
recall previous commands. If you make a mistake, the DELETE key OR
the backspace key may be used to correct the error; however, one of
these two keys may be inoperable on particular systems.
'matlab' uses variables that are defined to be matrices. A
matrix is a collection of numerical values that are organized into
a specific configuration of rows and columns. The number of rows
and columns can be any number, for example, 3 rows and 4 columns
define a 3 x 4 matrix which has 12 elements in total. A scalar is
represented by a 1 x 1 matrix in matlab. A vector of n dimensions
or elements can be represented by a n x 1 matrix, in which case it
is called a column vector, or a vector can be represented by a 1 x
n matrix, in which case it is called a row vector of n elements.
The matrix name can be any group of letters and numbers up to 19,
but always beginning with a letter. Thus 'x1' can be a variable
name, but '1x' is illegal. 'supercalafragilesticexpealladotious'
can be a variable name; however, only the first 19 characters will
be stored! Understand that 'matlab' is "case sensitive", that is,
it treats the name 'C' and 'c' as two different variables.
Similarly, 'MID' and 'Mid' are treated as two different variables.
Here are examples of matrices that could be defined in 'matlab'.
Note that the set of numerical values or elements of the matrix are
bounded by brackets ......[ ].
c = 5.66 or c = [5.66]
c is a scalar or
a 1 x 1 matrix
x = [ 3.5, 33.22, 24.5 ]
x is a row vector or
1 x 3 matrix
x1 = [ 2

x1 is column vector or
5
3
-1]
A=[1 2 4
2 -2 2
0 3 5
5 4 9]

4 x 1 matrix

A is a 4 x 3 matrix

An individual element of a matrix can be specified with the
notation A(i,j) or Ai,j for the generalized element, or by A(4,1)=5
for a specific element.
When 'matlab' prints a matrix on the monitor, it will be organized
according to the size specification of the matrix, with each row
appearing on a unique row of the monitor screen and with each
column aligned vertically and right-justified.
The numerical values that are assigned to the individual elements
of a matrix can be entered into the variable assignment in a number
of ways. The simplest way is by direct keyboard entry; however,
large data sets may be more conveniently entered through the use of
stored files or by generating the element values using matlab
expressions. First, we will look at the use of the keyboard for
direct entry.
KEYBOARD DEFINITION OR ENTRY FOR A MATRIX
A matrix can be defined by a number of matlab expressions. Examples
are listed below for a 1 x 3 row vector, x, whose elements are
x(1) = 2, x(2) = 4 and x(3) = -1.
x = [ 2 4 -1 ]

or x=[2 4 -1]

or

x = [ 2,4,-1 ]

(A keystroke 'enter' follows each of the above matlab statements.)
Notice that brackets must be used to open and close the set of
numbers, and notice that commas or blanks may be used as delimiters
between the fields defining the elements of the matrix. Blanks used
around the = sign and the brackets are superfluous; however, they
sometimes make the statement more readable.
A 2x4 matrix, y, whose elements are y(1,1)=0, y(1,2) = y(1,3) = 2,
y(1,4) = 3, y(2,1) = 5, y(2,2) = -3, y(2,3) = 6 and y(2,4) = 4 can
be defined
y=[0223
5 -3 6 4 ]
or
y = [ 0 2 2 3 ; 5 -3 6 4 ]
The semicolon ";" is used to differentiate the matrix rows when
they appear on a single line for data entry.
The elements of a matrix can be defined with algebraic expressions
placed at the appropriate location of the element. Thus
a = [ sin(pi/2) sqrt(2) 3+4 6/3 exp(2) ]
defines the matrix
a = [ 1.0000 1.4142 7.0000 2.0000 7.3891 ]
A matrix can be defined by augmenting previously defined matrices.
Recalling the matrix, x, defined earlier
x1 = [ x 5 8 ] creates the result
x1 = [ 2 4 -1 5 8 ]
The expression
x(5) = 8
creates
x = [ 2 4 -1 0 8 ]
Notice that the value "0" is substituted for x(4) which has not
been explicitly defined.
Recalling the definition of matrix, y, above, the expressions
c=[4 5 6 3]
z = [ y;c ]
creates
z=[0 2 2 3
5 -3 6 4
4 5 6 3]
Note that every time a matrix is defined and an 'enter' keystroke
is executed, matlab echoes back the result. TO CANCEL THIS ECHO,
THE MATLAB COMMAND LINE CAN INCLUDE A SEMICOLON AT THE END
OF THE
LINE BEFORE THE KEYSTROKE 'ENTER'.
z=[y;c];
LINE CONTINUATION
Occasionally, a line is so long that it can not be expressed in
the 80 spaces available on a line, in which case a line
continuation is needed. In matlab, the ellipsis defining a line
continuation is three successive periods, as in "...". Thus
4 + 5 + 3 ...
+ 1 + 10 + 2 ...
+5
gives the result
ans = 30
Notice that in this simple arithmetic operation, no matrix was
defined. When such an operation is executed in matlab, the result
is assigned to the matrix titled "ans". A subsequent operation
without an assignment to a specific matrix name will replace the
results in 'ans' by the result of the next operation. In the above,
'ans' is a 1x1 matrix, but it need not be so in general.
BEFORE YOU QUIT THIS SESSION !!!!!
If this is your first lesson using matlab, execute the matlab
commands 'who' and whos' before you 'quit'. Note that each of these
commands lists the matrices you have defined in this session on the
computer. The command 'whos' also tells you the properties of each
matrix, including the number of elements, the row and column size
(row x column) and whether the elements are complex or real.
IMPORTANT! If you execute the matlab command 'save' before you
quit, all of the matrices that have been defined will be saved in
a file titled matlab.mat stored in your workspace. Should you
desire to save specific matrices during any session, the command
'save' followed by the name of the matrix can be executed. More
detail on how to save and recall your matrices is discussed in
Lesson 2.
PRACTICE PROBLEMS
Determine the size and result for the following matrices.
Subsequently, carry out the operations on matlab that define the
matrices, and check your results using the 'whos' statement.
1. a = [1,0,0,0,0,1]
2. b = [2;4;6;10]
3. c = [5 3 5; 6 2 -3]
4. d= [3 4
5 7
9 10 ]
5. e = [3 5 10 0; 0 0 ...
0 3; 3 9 9 8 ]
6. t = [4 24 9]
q = [t 0 t]
7. x = [ 3 6 ]
y = [d;x]
z = [x;d]
8. r = [ c; x,5]
9. v = [ c(2,1); b ]
10. a(2,1) = -3 (NOTE: Recall matrix "a" was defined in (1)
above.)
Back to Matlab In-House Tutorials
PRACTICE PROBLEMS
Determine the size and result for the following matrices.
Subsequently, carry out the operations on matlab that define the
matrices, and check your results using the 'whos' statement.
1. a = [1,0,0,0,0,1]
2. b = [2;4;6;10]
3. c = [5 3 5; 6 2 -3]
4. d= [3 4
5 7
9 10 ]
5. e = [3 5 10 0; 0 0 ...
0 3; 3 9 9 8 ]
6. t = [4 24 9]
q = [t 0 t]
7. x = [ 3 6 ]
y = [d;x]
z = [x;d]
8. r = [ c; x,5]
9. v = [ c(2,1); b ]
10. a(2,1) = -3 (NOTE: Recall matrix "a" was defined in (1)
above.)
Back to Matlab In-House Tutorials

More Related Content

What's hot

Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
THEMASTERBLASTERSVID
 
INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notes
Infinity Tech Solutions
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Satish Gummadi
 
C,C++ In Matlab
C,C++ In MatlabC,C++ In Matlab
C,C++ In Matlab
DataminingTools Inc
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Khulna University
 
Matlab ch1 (3)
Matlab ch1 (3)Matlab ch1 (3)
Matlab ch1 (3)
mohsinggg
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
BinodKumarSahu5
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
pramodkumar1804
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
Velalar College of Engineering and Technology
 
MATLAB BASICS
MATLAB BASICSMATLAB BASICS
MATLAB BASICSbutest
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
Infinity Tech Solutions
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
Make Mannan
 
Ch1
Ch1Ch1
Matlab intro notes
Matlab intro notesMatlab intro notes
Matlab intro notes
pawanss
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorial
Jia-Bin Huang
 
Ses 2 matrix opt
Ses 2 matrix optSes 2 matrix opt
Ses 2 matrix opt
metnashikiom2011-13
 
Introduction to MATLAB Programming and Numerical Methods for Engineers 1st Ed...
Introduction to MATLAB Programming and Numerical Methods for Engineers 1st Ed...Introduction to MATLAB Programming and Numerical Methods for Engineers 1st Ed...
Introduction to MATLAB Programming and Numerical Methods for Engineers 1st Ed...
AmeryWalters
 

What's hot (20)

Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notes
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
C,C++ In Matlab
C,C++ In MatlabC,C++ In Matlab
C,C++ In Matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab ch1 (3)
Matlab ch1 (3)Matlab ch1 (3)
Matlab ch1 (3)
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
 
MATLAB BASICS
MATLAB BASICSMATLAB BASICS
MATLAB BASICS
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
 
Tutorial2
Tutorial2Tutorial2
Tutorial2
 
Ch1
Ch1Ch1
Ch1
 
Matlab intro notes
Matlab intro notesMatlab intro notes
Matlab intro notes
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorial
 
Ses 2 matrix opt
Ses 2 matrix optSes 2 matrix opt
Ses 2 matrix opt
 
Introduction to MATLAB Programming and Numerical Methods for Engineers 1st Ed...
Introduction to MATLAB Programming and Numerical Methods for Engineers 1st Ed...Introduction to MATLAB Programming and Numerical Methods for Engineers 1st Ed...
Introduction to MATLAB Programming and Numerical Methods for Engineers 1st Ed...
 

Similar to matlab Lesson 1

Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
Mohammad Alauddin
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Vikash Jakhar
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
raghav415187
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to Matlab
Tariq kanher
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Mohd Esa
 
Matlab
MatlabMatlab
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
krajeshk1980
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
AkashSingh728626
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Dnyanesh Patil
 
Matlab Overviiew 2
Matlab Overviiew 2Matlab Overviiew 2
Matlab Overviiew 2
Nazim Naeem
 
Matlabch01
Matlabch01Matlabch01
Matlabch01
Mohammad Ayyash
 

Similar to matlab Lesson 1 (20)

Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Brief Introduction to Matlab
Brief  Introduction to MatlabBrief  Introduction to Matlab
Brief Introduction to Matlab
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Matlab
MatlabMatlab
Matlab
 
Matlab
MatlabMatlab
Matlab
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
bobok
bobokbobok
bobok
 
Matlab Overviiew 2
Matlab Overviiew 2Matlab Overviiew 2
Matlab Overviiew 2
 
Matlabch01
Matlabch01Matlabch01
Matlabch01
 
Lesson 6
Lesson 6Lesson 6
Lesson 6
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 

More from Vinnu Vinay (10)

Matlab tut3
Matlab tut3Matlab tut3
Matlab tut3
 
Matlab tut2
Matlab tut2Matlab tut2
Matlab tut2
 
Matlab summary
Matlab summaryMatlab summary
Matlab summary
 
Lesson 8
Lesson 8Lesson 8
Lesson 8
 
Lesson 7
Lesson 7Lesson 7
Lesson 7
 
Lesson 5
Lesson 5Lesson 5
Lesson 5
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Lesson 2
Lesson 2Lesson 2
Lesson 2
 
Matlabtut1
Matlabtut1Matlabtut1
Matlabtut1
 

Recently uploaded

Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 

Recently uploaded (20)

Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

matlab Lesson 1

  • 1. Last modified:January 1, 1970 GMT An Introduction to Matlab(tm): Lesson 1 Some basic commands you will need: matlab loads the program matlab into your workspace quit quits matlab, returning you to the operating system exit same as quit who lists all of the variables in your matlab workspace whos list the variables and describes their matrix size NOTE - When using the workstations, clicking on UP ARROW will recall previous commands. If you make a mistake, the DELETE key OR the backspace key may be used to correct the error; however, one of these two keys may be inoperable on particular systems. 'matlab' uses variables that are defined to be matrices. A matrix is a collection of numerical values that are organized into a specific configuration of rows and columns. The number of rows and columns can be any number, for example, 3 rows and 4 columns define a 3 x 4 matrix which has 12 elements in total. A scalar is represented by a 1 x 1 matrix in matlab. A vector of n dimensions or elements can be represented by a n x 1 matrix, in which case it is called a column vector, or a vector can be represented by a 1 x n matrix, in which case it is called a row vector of n elements. The matrix name can be any group of letters and numbers up to 19, but always beginning with a letter. Thus 'x1' can be a variable name, but '1x' is illegal. 'supercalafragilesticexpealladotious' can be a variable name; however, only the first 19 characters will be stored! Understand that 'matlab' is "case sensitive", that is, it treats the name 'C' and 'c' as two different variables. Similarly, 'MID' and 'Mid' are treated as two different variables. Here are examples of matrices that could be defined in 'matlab'. Note that the set of numerical values or elements of the matrix are bounded by brackets ......[ ]. c = 5.66 or c = [5.66] c is a scalar or a 1 x 1 matrix x = [ 3.5, 33.22, 24.5 ] x is a row vector or 1 x 3 matrix x1 = [ 2 x1 is column vector or
  • 2. 5 3 -1] A=[1 2 4 2 -2 2 0 3 5 5 4 9] 4 x 1 matrix A is a 4 x 3 matrix An individual element of a matrix can be specified with the notation A(i,j) or Ai,j for the generalized element, or by A(4,1)=5 for a specific element. When 'matlab' prints a matrix on the monitor, it will be organized according to the size specification of the matrix, with each row appearing on a unique row of the monitor screen and with each column aligned vertically and right-justified. The numerical values that are assigned to the individual elements of a matrix can be entered into the variable assignment in a number of ways. The simplest way is by direct keyboard entry; however, large data sets may be more conveniently entered through the use of stored files or by generating the element values using matlab expressions. First, we will look at the use of the keyboard for direct entry. KEYBOARD DEFINITION OR ENTRY FOR A MATRIX A matrix can be defined by a number of matlab expressions. Examples are listed below for a 1 x 3 row vector, x, whose elements are x(1) = 2, x(2) = 4 and x(3) = -1. x = [ 2 4 -1 ] or x=[2 4 -1] or x = [ 2,4,-1 ] (A keystroke 'enter' follows each of the above matlab statements.) Notice that brackets must be used to open and close the set of numbers, and notice that commas or blanks may be used as delimiters between the fields defining the elements of the matrix. Blanks used around the = sign and the brackets are superfluous; however, they sometimes make the statement more readable. A 2x4 matrix, y, whose elements are y(1,1)=0, y(1,2) = y(1,3) = 2, y(1,4) = 3, y(2,1) = 5, y(2,2) = -3, y(2,3) = 6 and y(2,4) = 4 can be defined
  • 3. y=[0223 5 -3 6 4 ] or y = [ 0 2 2 3 ; 5 -3 6 4 ] The semicolon ";" is used to differentiate the matrix rows when they appear on a single line for data entry. The elements of a matrix can be defined with algebraic expressions placed at the appropriate location of the element. Thus a = [ sin(pi/2) sqrt(2) 3+4 6/3 exp(2) ] defines the matrix a = [ 1.0000 1.4142 7.0000 2.0000 7.3891 ] A matrix can be defined by augmenting previously defined matrices. Recalling the matrix, x, defined earlier x1 = [ x 5 8 ] creates the result x1 = [ 2 4 -1 5 8 ] The expression x(5) = 8 creates x = [ 2 4 -1 0 8 ] Notice that the value "0" is substituted for x(4) which has not been explicitly defined. Recalling the definition of matrix, y, above, the expressions c=[4 5 6 3] z = [ y;c ] creates z=[0 2 2 3 5 -3 6 4 4 5 6 3]
  • 4. Note that every time a matrix is defined and an 'enter' keystroke is executed, matlab echoes back the result. TO CANCEL THIS ECHO, THE MATLAB COMMAND LINE CAN INCLUDE A SEMICOLON AT THE END OF THE LINE BEFORE THE KEYSTROKE 'ENTER'. z=[y;c]; LINE CONTINUATION Occasionally, a line is so long that it can not be expressed in the 80 spaces available on a line, in which case a line continuation is needed. In matlab, the ellipsis defining a line continuation is three successive periods, as in "...". Thus 4 + 5 + 3 ... + 1 + 10 + 2 ... +5 gives the result ans = 30 Notice that in this simple arithmetic operation, no matrix was defined. When such an operation is executed in matlab, the result is assigned to the matrix titled "ans". A subsequent operation without an assignment to a specific matrix name will replace the results in 'ans' by the result of the next operation. In the above, 'ans' is a 1x1 matrix, but it need not be so in general. BEFORE YOU QUIT THIS SESSION !!!!! If this is your first lesson using matlab, execute the matlab commands 'who' and whos' before you 'quit'. Note that each of these commands lists the matrices you have defined in this session on the computer. The command 'whos' also tells you the properties of each matrix, including the number of elements, the row and column size (row x column) and whether the elements are complex or real. IMPORTANT! If you execute the matlab command 'save' before you quit, all of the matrices that have been defined will be saved in a file titled matlab.mat stored in your workspace. Should you desire to save specific matrices during any session, the command 'save' followed by the name of the matrix can be executed. More detail on how to save and recall your matrices is discussed in Lesson 2.
  • 5. PRACTICE PROBLEMS Determine the size and result for the following matrices. Subsequently, carry out the operations on matlab that define the matrices, and check your results using the 'whos' statement. 1. a = [1,0,0,0,0,1] 2. b = [2;4;6;10] 3. c = [5 3 5; 6 2 -3] 4. d= [3 4 5 7 9 10 ] 5. e = [3 5 10 0; 0 0 ... 0 3; 3 9 9 8 ] 6. t = [4 24 9] q = [t 0 t] 7. x = [ 3 6 ] y = [d;x] z = [x;d] 8. r = [ c; x,5] 9. v = [ c(2,1); b ] 10. a(2,1) = -3 (NOTE: Recall matrix "a" was defined in (1) above.) Back to Matlab In-House Tutorials
  • 6. PRACTICE PROBLEMS Determine the size and result for the following matrices. Subsequently, carry out the operations on matlab that define the matrices, and check your results using the 'whos' statement. 1. a = [1,0,0,0,0,1] 2. b = [2;4;6;10] 3. c = [5 3 5; 6 2 -3] 4. d= [3 4 5 7 9 10 ] 5. e = [3 5 10 0; 0 0 ... 0 3; 3 9 9 8 ] 6. t = [4 24 9] q = [t 0 t] 7. x = [ 3 6 ] y = [d;x] z = [x;d] 8. r = [ c; x,5] 9. v = [ c(2,1); b ] 10. a(2,1) = -3 (NOTE: Recall matrix "a" was defined in (1) above.) Back to Matlab In-House Tutorials