SlideShare a Scribd company logo
1 of 7
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

What's hot

Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IVijay Kumar Gupta
 
Matlab for diploma students(1)
Matlab for diploma students(1)Matlab for diploma students(1)
Matlab for diploma students(1)Retheesh Raj
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABRavikiran A
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab IntroductionDaniel Moore
 
MATLAB BASICS
MATLAB BASICSMATLAB BASICS
MATLAB BASICSbutest
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlabkrajeshk1980
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabBilawalBaloch1
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlabaman gupta
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Randa Elanwar
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabTarun Gehlot
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab OverviiewNazim Naeem
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to MatlabAmr Rashed
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)harman kaur
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABSarah Hussein
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrixSaidur Rahman
 

What's hot (20)

Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - I
 
Matlab for diploma students(1)
Matlab for diploma students(1)Matlab for diploma students(1)
Matlab for diploma students(1)
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
MATLAB BASICS
MATLAB BASICSMATLAB BASICS
MATLAB BASICS
 
MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab Overviiew
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)Matlab 1(operations on_matrix)
Matlab 1(operations on_matrix)
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab
MatlabMatlab
Matlab
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrix
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 

Similar to Matlab tut2

From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondMahuaPal6
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systemsRaghav Shetty
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
Introduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfIntroduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfDrAzizulHasan1
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxprashantkumarchinama
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1Elaf A.Saeed
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introductionideas2ignite
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantssdharmesh69
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTtejas1235
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxlekhacce
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013amanabr
 

Similar to Matlab tut2 (20)

From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systems
 
Matlab
MatlabMatlab
Matlab
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Introduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfIntroduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdf
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
Basic matlab for beginners
Basic matlab for beginnersBasic matlab for beginners
Basic matlab for beginners
 
MATLAB guide
MATLAB guideMATLAB guide
MATLAB guide
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantss
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENT
 
Matlab 1 level_1
Matlab 1 level_1Matlab 1 level_1
Matlab 1 level_1
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsx
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 

More from Vinnu Vinay (10)

Matlab tut3
Matlab tut3Matlab tut3
Matlab tut3
 
Lesson 8
Lesson 8Lesson 8
Lesson 8
 
Lesson 7
Lesson 7Lesson 7
Lesson 7
 
Lesson 6
Lesson 6Lesson 6
Lesson 6
 
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
 
matlab Lesson 1
matlab Lesson 1matlab Lesson 1
matlab Lesson 1
 
Matlabtut1
Matlabtut1Matlabtut1
Matlabtut1
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

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