SlideShare a Scribd company logo
MATLAB Summary
MATLAB (matrix algebra)
Matlab is a commercial "Matrix Laboratory" package which operates as an interactive
programming environment. It is a mainstay of the Mathematics Department software
lineup and is also available for PC's and Macintoshes and may be found on the CIRCA
VAXes. Matlab is well adapted to numerical experiments since the underlying algorithms
for Matlab's builtin functions and supplied m-files are based on the standard libraries
LINPACK and EISPACK.
Matlab program and script files always have filenames ending with ".m"; the
programming language is exceptionally straightforward since almost every data object is
assumed to be an array. Graphical output is available to supplement numerical results.
Online help is available from the Matlab prompt (a double arrow), both generally (listing
all available commands):
>> help
[a long list of help topics follows]

and for specific commands:
>> help fft
[a help message on the fft function follows].

Paper documentation is on the document shelf in compact black books and locally
generated tutorials are available and are used in courses.

How to quit Matlab
The answer to the most popular question concerning any program is this: leave a Matlab
session by typing
quit

or by typing
exit

to the Matlab prompt.

Batch jobs
Matlab is most often used interactively, but "batch" or "background" jobs can be
performed as well. Debug your commands interactively and store them in a file
(`script.m', for example). To start a background session from your input file and to put
the output and error messages into another file (`script.out', for example), enter this line at
the system prompt:
nice matlab < script.m >& script.out

&

You can then do other work at the machine or logout while Matlab grinds out your
program. Here's an explanation of the sequence of commands above.
1. The "nice" command lowers matlab's priority so that interactive users have first
crack at the CPU. You must do this for noninteractive Matlab sessions because of
the load that number--crunching puts on the CPU.
2. The "< script.m" means that input is to be read from the file script.m.
3. The ">& script.out" is an instruction to send program output and error output to
the file script.out. (It is important to include the first ampersand (&) so that error
messages are sent to your file rather than to the screen -- if you omit the
ampersand then your error messages may turn up on other people's screens and
your popularity will plummet.)
4. Finally, the concluding ampersand (&) puts the whole job into background.
(Of course, the file names used above are not important -- these are just examples to
illustrate the format of the command string.)
A quick tutorial on Matlab is available in the next Info node in this file. (Touch the "n"
key to go there now, or return to the menu in the Top node for this file.)

MATLAB Tutorial
MATLAB Tutorial (based on work of R. Smith,
November 1988 and later)
This is an interactive introduction to MATLAB. I have provided a sequence of
commands for you to type in. The designation RET means that you should type the
"return" key; this is implicit after a command.
To bring up MATLAB from from the operating system prompt
lab%

you should type matlab
lab% matlab RET

This will present the prompt
>>

You are now in MATLAB.
If you are using the X Window system on the Mathematics Department workstations then
you can also start MATLAB from the Main Menu by selecting "matlab" from the "Math
Applications" submenu. A window should pop up and start MATLAB. When you run
MATLAB under the window system, whether you start from the menu or a system
prompt, a small MATLAB logo window will pop up while the program is loading and
disappear when MATLAB is ready to use.
When you are ready to leave, type exit
>> exit RET
In the course of the tutorial if you get stuck on what a command means type
>> help <command name> RET

and then try the command again.
You should record the outcome of the commands and experiments in a notebook.
Remark: Depending on the Info reader you are using to navigate this tutorial, you might
be able to cut and paste many of the examples directly into Matlab.

Building Matrices
Matlab has many types of matrices which are built into the system. A 7 by 7 matrix with
random entries is produced by typing
rand(7)

You can generate random matrices of other sizes and get help on the rand command
within matlab:
rand(2,5)
help rand

Another special matrix, called a Hilbert matrix, is a standard example in numerical linear
algebra.
hilb(5)
help hilb

A 5 by 5 magic square is given by the next command:
magic(5)
help magic

A magic square is a square matrix which has equal sums along all its rows and columns.
We'll use matrix multiplication to check this property a bit later.
Some of the standard matrices from linear algebra are easily produced:
eye(6)
zeros(4,7)
ones(5)
You can also build matrices of your own with any entries that you may want.
[1

2

3

5

7

9]

[1, 2, 3; 4, 5, 6; 7, 8, 9]
[1

2 RET

3

4 RET 5

6]

[Note that if you are using cut-and-paste features of a window system or editor to copy
these examples into Matlab then you should not use cut-and-paste and the last line above.
Type it in by hand, touching the Return or Enter key where you see RET, and check to see
whether the carriage returns make any difference in Matlab's output.]
Matlab syntax is convenient for blocked matrices:
[eye(2);zeros(2)]
[eye(2);zeros(3)]
[eye(2),ones(2,3)]

Did any of the last three examples produce error messages? What is the problem?

Variables
Matlab has built-in variables like pi, eps, and ans. You can learn their values from the
Matlab interpreter.
pi
eps
help eps

At any time you want to know the active variables you can use who:
who
help

who

The variable ans will keep track of the last output which was not assigned to another
variable.
magic(6)
ans
x = ans
x = [x, eye(6)]
x

Since you have created a new variable, x, it should appear as an active variable.
who

To remove a variable, try this:
clear x
x
who

Functions
a = magic(4)

Take the transpose of a:
a'

Note that if the matrix A has complex numbers as entries then the Matlab function taking
A to A' will compute the transpose of the conjugate of A rather than the transpose of A.
Other arithmetic operations are easy to perform.
3*a
-a
a+(-a)
b = max(a)
max(b)
Some Matlab functions can return more than one value. In the case of max the interpreter
returns the maximum value and also the column index where the maximum value occurs.
[m, i] = max(b)
min(a)
b = 2*ones(a)
a*b
a

We can use matrix multiplication to check the "magic" property of magic squares.
A = magic(5)
b = ones(5,1)
A*b
v = ones(1,5)
v*A

Matlab has a convention in which a dot in front of an operation usually changes the
operation. In the case of multiplication, a.*b will perform entry-by-entry multiplic
Some Matlab functions can return more than one value. In the case of max the interpreter
returns the maximum value and also the column index where the maximum value occurs.
[m, i] = max(b)
min(a)
b = 2*ones(a)
a*b
a

We can use matrix multiplication to check the "magic" property of magic squares.
A = magic(5)
b = ones(5,1)
A*b
v = ones(1,5)
v*A

Matlab has a convention in which a dot in front of an operation usually changes the
operation. In the case of multiplication, a.*b will perform entry-by-entry multiplic

More Related Content

DOC
Matlab summary
Vinnu Vinay
 
PPT
How to work on Matlab.......
biinoida
 
PPTX
Programming Environment in Matlab
DataminingTools Inc
 
PDF
Matlab introduction lecture 1
Mohamed Awni
 
PPT
Brief Introduction to Matlab
Tariq kanher
 
PPTX
Matlab introduction
Ameen San
 
PPTX
All About MATLAB
Multisoft Virtual Academy
 
PPSX
Matlab basic and image
Divyanshu Rasauria
 
Matlab summary
Vinnu Vinay
 
How to work on Matlab.......
biinoida
 
Programming Environment in Matlab
DataminingTools Inc
 
Matlab introduction lecture 1
Mohamed Awni
 
Brief Introduction to Matlab
Tariq kanher
 
Matlab introduction
Ameen San
 
All About MATLAB
Multisoft Virtual Academy
 
Matlab basic and image
Divyanshu Rasauria
 

What's hot (20)

PDF
Matlab Tutorial for Beginners - I
Vijay Kumar Gupta
 
PPTX
Matlab for diploma students(1)
Retheesh Raj
 
PPTX
Introduction to MATLAB
Ravikiran A
 
PPT
Matlab Introduction
Daniel Moore
 
DOCX
MATLAB BASICS
butest
 
PDF
MATLAB INTRODUCTION
Dr. Krishna Mohbey
 
PPTX
Importance of matlab
krajeshk1980
 
PPT
Introduction to matlab
BilawalBaloch1
 
PPT
Introduction to Matlab
aman gupta
 
PPTX
Introduction to matlab lecture 1 of 4
Randa Elanwar
 
PPT
Introduction to matlab
Tarun Gehlot
 
PPT
Matlab Overviiew
Nazim Naeem
 
PDF
Introduction to Matlab
Amr Rashed
 
PPT
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
reddyprasad reddyvari
 
PPTX
Matlab 1(operations on_matrix)
harman kaur
 
PDF
EE6711 Power System Simulation Lab manual
Velalar College of Engineering and Technology
 
PDF
Introduction to MATLAB
Sarah Hussein
 
PPTX
Matlab
sandhya jois
 
PPTX
Basic matlab and matrix
Saidur Rahman
 
PPTX
Matlab ppt
chestialtaff
 
Matlab Tutorial for Beginners - I
Vijay Kumar Gupta
 
Matlab for diploma students(1)
Retheesh Raj
 
Introduction to MATLAB
Ravikiran A
 
Matlab Introduction
Daniel Moore
 
MATLAB BASICS
butest
 
MATLAB INTRODUCTION
Dr. Krishna Mohbey
 
Importance of matlab
krajeshk1980
 
Introduction to matlab
BilawalBaloch1
 
Introduction to Matlab
aman gupta
 
Introduction to matlab lecture 1 of 4
Randa Elanwar
 
Introduction to matlab
Tarun Gehlot
 
Matlab Overviiew
Nazim Naeem
 
Introduction to Matlab
Amr Rashed
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
reddyprasad reddyvari
 
Matlab 1(operations on_matrix)
harman kaur
 
EE6711 Power System Simulation Lab manual
Velalar College of Engineering and Technology
 
Introduction to MATLAB
Sarah Hussein
 
Matlab
sandhya jois
 
Basic matlab and matrix
Saidur Rahman
 
Matlab ppt
chestialtaff
 
Ad

Similar to Matlab tut2 (20)

PPTX
From zero to MATLAB hero: Mastering the basics and beyond
MahuaPal6
 
PDF
interfacing matlab with embedded systems
Raghav Shetty
 
PDF
Matlab
Hira Sisodiya
 
PDF
Matlab guide
aibad ahmed
 
DOCX
Introduction to matlab
Indrani Jangete
 
PPT
Introduction to Matlab.ppt
Ravibabu Kancharla
 
PPT
Matlab practical and lab session
Dr. Krishna Mohbey
 
PDF
Introduction to Matlab for Engineering & Science Students.pdf
Dr Azizul Hasan
 
PPT
Matlab anilkumar
THEMASTERBLASTERSVID
 
PPTX
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
PDF
MATLAB Basics-Part1
Elaf A.Saeed
 
DOCX
Mmc manual
Urvi Surat
 
PDF
Basic matlab for beginners
Kwabena Owusu-Agyemang
 
DOCX
MATLAB guide
Prerna Rathore
 
PPTX
Matlab Introduction
ideas2ignite
 
DOCX
KEVIN MERCHANT DOCUMENT
tejas1235
 
DOCX
Kevin merchantss
dharmesh69
 
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
PPTX
Chapter 1 _ Introduction to Matlab.pptx
ThyTinaPhan
 
PPTX
Matlab 1 level_1
Ahmed Farouk
 
From zero to MATLAB hero: Mastering the basics and beyond
MahuaPal6
 
interfacing matlab with embedded systems
Raghav Shetty
 
Matlab guide
aibad ahmed
 
Introduction to matlab
Indrani Jangete
 
Introduction to Matlab.ppt
Ravibabu Kancharla
 
Matlab practical and lab session
Dr. Krishna Mohbey
 
Introduction to Matlab for Engineering & Science Students.pdf
Dr Azizul Hasan
 
Matlab anilkumar
THEMASTERBLASTERSVID
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
MATLAB Basics-Part1
Elaf A.Saeed
 
Mmc manual
Urvi Surat
 
Basic matlab for beginners
Kwabena Owusu-Agyemang
 
MATLAB guide
Prerna Rathore
 
Matlab Introduction
ideas2ignite
 
KEVIN MERCHANT DOCUMENT
tejas1235
 
Kevin merchantss
dharmesh69
 
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
Chapter 1 _ Introduction to Matlab.pptx
ThyTinaPhan
 
Matlab 1 level_1
Ahmed Farouk
 
Ad

More from Vinnu Vinay (10)

DOC
Matlab tut3
Vinnu Vinay
 
DOC
Lesson 8
Vinnu Vinay
 
DOC
Lesson 7
Vinnu Vinay
 
DOC
Lesson 6
Vinnu Vinay
 
DOC
Lesson 5
Vinnu Vinay
 
DOC
Lesson 4
Vinnu Vinay
 
DOC
Lesson 3
Vinnu Vinay
 
DOC
Lesson 2
Vinnu Vinay
 
DOC
matlab Lesson 1
Vinnu Vinay
 
DOC
Matlabtut1
Vinnu Vinay
 
Matlab tut3
Vinnu Vinay
 
Lesson 8
Vinnu Vinay
 
Lesson 7
Vinnu Vinay
 
Lesson 6
Vinnu Vinay
 
Lesson 5
Vinnu Vinay
 
Lesson 4
Vinnu Vinay
 
Lesson 3
Vinnu Vinay
 
Lesson 2
Vinnu Vinay
 
matlab Lesson 1
Vinnu Vinay
 
Matlabtut1
Vinnu Vinay
 

Recently uploaded (20)

PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Software Development Methodologies in 2025
KodekX
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 

Matlab tut2

  • 1. MATLAB Summary MATLAB (matrix algebra) Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environment. It is a mainstay of the Mathematics Department software lineup and is also available for PC's and Macintoshes and may be found on the CIRCA VAXes. Matlab is well adapted to numerical experiments since the underlying algorithms for Matlab's builtin functions and supplied m-files are based on the standard libraries LINPACK and EISPACK. Matlab program and script files always have filenames ending with ".m"; the programming language is exceptionally straightforward since almost every data object is assumed to be an array. Graphical output is available to supplement numerical results. Online help is available from the Matlab prompt (a double arrow), both generally (listing all available commands): >> help [a long list of help topics follows] and for specific commands: >> help fft [a help message on the fft function follows]. Paper documentation is on the document shelf in compact black books and locally generated tutorials are available and are used in courses. How to quit Matlab The answer to the most popular question concerning any program is this: leave a Matlab session by typing quit or by typing exit to the Matlab prompt. Batch jobs Matlab is most often used interactively, but "batch" or "background" jobs can be performed as well. Debug your commands interactively and store them in a file (`script.m', for example). To start a background session from your input file and to put the output and error messages into another file (`script.out', for example), enter this line at the system prompt: nice matlab < script.m >& script.out & You can then do other work at the machine or logout while Matlab grinds out your program. Here's an explanation of the sequence of commands above.
  • 2. 1. The "nice" command lowers matlab's priority so that interactive users have first crack at the CPU. You must do this for noninteractive Matlab sessions because of the load that number--crunching puts on the CPU. 2. The "< script.m" means that input is to be read from the file script.m. 3. The ">& script.out" is an instruction to send program output and error output to the file script.out. (It is important to include the first ampersand (&) so that error messages are sent to your file rather than to the screen -- if you omit the ampersand then your error messages may turn up on other people's screens and your popularity will plummet.) 4. Finally, the concluding ampersand (&) puts the whole job into background. (Of course, the file names used above are not important -- these are just examples to illustrate the format of the command string.) A quick tutorial on Matlab is available in the next Info node in this file. (Touch the "n" key to go there now, or return to the menu in the Top node for this file.) MATLAB Tutorial MATLAB Tutorial (based on work of R. Smith, November 1988 and later) This is an interactive introduction to MATLAB. I have provided a sequence of commands for you to type in. The designation RET means that you should type the "return" key; this is implicit after a command. To bring up MATLAB from from the operating system prompt lab% you should type matlab lab% matlab RET This will present the prompt >> You are now in MATLAB. If you are using the X Window system on the Mathematics Department workstations then you can also start MATLAB from the Main Menu by selecting "matlab" from the "Math Applications" submenu. A window should pop up and start MATLAB. When you run MATLAB under the window system, whether you start from the menu or a system prompt, a small MATLAB logo window will pop up while the program is loading and disappear when MATLAB is ready to use. When you are ready to leave, type exit >> exit RET
  • 3. In the course of the tutorial if you get stuck on what a command means type >> help <command name> RET and then try the command again. You should record the outcome of the commands and experiments in a notebook. Remark: Depending on the Info reader you are using to navigate this tutorial, you might be able to cut and paste many of the examples directly into Matlab. Building Matrices Matlab has many types of matrices which are built into the system. A 7 by 7 matrix with random entries is produced by typing rand(7) You can generate random matrices of other sizes and get help on the rand command within matlab: rand(2,5) help rand Another special matrix, called a Hilbert matrix, is a standard example in numerical linear algebra. hilb(5) help hilb A 5 by 5 magic square is given by the next command: magic(5) help magic A magic square is a square matrix which has equal sums along all its rows and columns. We'll use matrix multiplication to check this property a bit later. Some of the standard matrices from linear algebra are easily produced: eye(6) zeros(4,7) ones(5)
  • 4. You can also build matrices of your own with any entries that you may want. [1 2 3 5 7 9] [1, 2, 3; 4, 5, 6; 7, 8, 9] [1 2 RET 3 4 RET 5 6] [Note that if you are using cut-and-paste features of a window system or editor to copy these examples into Matlab then you should not use cut-and-paste and the last line above. Type it in by hand, touching the Return or Enter key where you see RET, and check to see whether the carriage returns make any difference in Matlab's output.] Matlab syntax is convenient for blocked matrices: [eye(2);zeros(2)] [eye(2);zeros(3)] [eye(2),ones(2,3)] Did any of the last three examples produce error messages? What is the problem? Variables Matlab has built-in variables like pi, eps, and ans. You can learn their values from the Matlab interpreter. pi eps help eps At any time you want to know the active variables you can use who: who help who The variable ans will keep track of the last output which was not assigned to another variable. magic(6)
  • 5. ans x = ans x = [x, eye(6)] x Since you have created a new variable, x, it should appear as an active variable. who To remove a variable, try this: clear x x who Functions a = magic(4) Take the transpose of a: a' Note that if the matrix A has complex numbers as entries then the Matlab function taking A to A' will compute the transpose of the conjugate of A rather than the transpose of A. Other arithmetic operations are easy to perform. 3*a -a a+(-a) b = max(a) max(b)
  • 6. Some Matlab functions can return more than one value. In the case of max the interpreter returns the maximum value and also the column index where the maximum value occurs. [m, i] = max(b) min(a) b = 2*ones(a) a*b a We can use matrix multiplication to check the "magic" property of magic squares. A = magic(5) b = ones(5,1) A*b v = ones(1,5) v*A Matlab has a convention in which a dot in front of an operation usually changes the operation. In the case of multiplication, a.*b will perform entry-by-entry multiplic
  • 7. Some Matlab functions can return more than one value. In the case of max the interpreter returns the maximum value and also the column index where the maximum value occurs. [m, i] = max(b) min(a) b = 2*ones(a) a*b a We can use matrix multiplication to check the "magic" property of magic squares. A = magic(5) b = ones(5,1) A*b v = ones(1,5) v*A Matlab has a convention in which a dot in front of an operation usually changes the operation. In the case of multiplication, a.*b will perform entry-by-entry multiplic