SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
1
Introduction to Matlab
Introduction to Matlab
1. Vectors, matrices, and arithmetic
2. Plotting
3. Flow Constructs
4. Other Useful Things
2
Why use Matlab?
• Drawbacks:
Slow compared to C or Java
• Advantages:
Handles vector and matrices very nicely
Quick plotting and analysis
EXTENSIVE documentation (type ‘help’)
Lots of nice functions: FFT, fuzzy logic, neural
nets, numerical integration, OpenGL (!?)
Vectors and Matrices
• Can be run from command line or from *.m file
scalar: x = 3
vector: x = [1 0 0]
2D matrix: x = [1 0 0; 0 1 0; 0 0 1]
arbitrarily higher dimensions possible
• Can also use matrices / vectors as elements:
x = [1 2 3]
y = [ x 4 5 6]
3
Some Standard matrices
• ones(3,3) 3x3 of all ones
• zeros(3,3) 3x3 of all zeros
• eye(3,3) 3x3 identity
• rand(3) 3x3 random elements
• linspace(1,10,100)
linear spacing from 1 to 10, with 100
spacings (also logspace)
• x = 1:10
linear spacing from 1 to 10, counting by 1
Accessing elements
• MATLAB IS NOT ZERO INDEXED!
• x retrieves entire matrix x
• x(1,2) retrieves element at row 1, col 2
• x(1, 5:10) retrieves row 1, columns 5 to 10
• x(1,:) retrieves row 1, all columns
• Useful functions:
length(x) length of vector x (cols)
size(x) rows, cols of x
4
Matrix Operations
• For matrix operations
– Dimensions must agree
• Scalar operations
– Same as usual
• Scalar / matrix mixed
– Scalar + matrix = [scalar + matrix(x, y)]
– Scalar * matrix = [scalar * matrix(x, y)]
More Matrix Operations
• The ‘.’ operator
– “element by element” access
• Example:
– x = [1 2 3]; y = [4; 5; 6];
– x * y = 32
– x .* y = [4 10 18]
• For some functions :
– x ^ 2 ERROR!
– x . ^2 fine
5
More Matrix Operations
• x=1:12
• reshape(x, 3,4)
• a=2*ones(3,4)
• X.*a
• b=[1:3;1:3;1:3;1:3]
• X.*b
• y=reshape(x, 4,3)
• y.^b
Plotting
• 2D graphing
plot(x,y)
• Example:
x = linspace(-10,10,100)
y = x .^2
plot(x,y)
• Also:
z = x .^3
plot(x,z)
6
Plotting Example
basis = [
[1 0];
[0 0];
[0 1];
]';
square = [
[ 1 1]
[-1 1];
[-1 -1];
[ 1 -1];
[ 1 1];
]';
axis equal;
plot( sqrt(3), sqrt(3), 'w.');
plot( -sqrt(3), -sqrt(3), 'w.');
plot( basis(1,:), basis(2,:), 'k');
plot( square(1,:), square(2,:), 'b');pause
obj = S*square;
plot( obj(1,:), obj(2,:), 'r');pause
Plotting Examplebasis = [
[1 0];
[0 0];
[0 1];
[1 0];
]';
square = [
[ 1 1];
[-1 1];
[-1 -1];
[ 1 -1];
[ 1 1];
7
More Plotting
• Graphics Window
– To open a new graph, type ‘figure’
• Multiple data sets:
– Type ‘hold on’ to add new plot to current graph
– Type ‘hold off’ to resume default mode
• Make your graph beautiful:
– title(‘apples over oranges’)
– xtitle(‘apples’)
– ytitle(‘oranges’)
3D Plotting
• 3D plots – plot an outer product
x = 1:10
y = 1:10
z = x’ * y
mesh(x,y,z)
Single quote ‘ means transpose
8
Flow Control
• IF block
if (<condition>)
<body>
elseif
<body>
end
• WHILE block
while (<condition>)
<body>
end
Conditions same as C, ( ==, >=, <=) except != is ~=
More Flow Control
• FOR block
for i = 1:10
<body>
end
• SWITCH statement
switch <expression>
case <condition>,
<statement>
otherwise <condition>,
<statement>
end
9
Other Language Features
• Matlab language is pretty sophisticated
– Functions
Stored in a *.m file of the same name:
function <return variable> = <function name>(<args>)
<function body>
– Structs
• point.x = 2; point.y = 3; point.z = 4;
Useful Commands
• Single quote is transpose
• % same as // comment in C, Java
No /* block comments */
• ; suppresses printing
• More:
max(x) min(x)
mean(x) median(x)
abs(x) dot(x,y)
cross(x,y) flops (flops in this session)
10
Useful Constants
• Inf infinity
• NaN Not a number (div by zero)
• eps machine epsilon (precision)
• ans most recent unassigned answer
• pi 3.14159….
• i and j Matlab supports imaginary
numbers!
Programming
• Wrong:
for x = 1:10
for y = 1:10
foo(x,y) = 2 * bar(x,y)
end
end
• Right:
foo = 2 * bar;
• Matlab is optimized for vectorization
11
Symbolic Maths
• Symbolic mathematics can be done using Matalb:
a = sqrt(sym(2))
a =
2^(1/2)
th=sym('th');
rt=sym([cos(th) sin(th) 0;-sin(th) cos(th) 0;0 0 1]);
rt =
[ cos(th), sin(th), 0]
[ -sin(th), cos(th), 0]
[ 0, 0, 1]
Good luck

Contenu connexe

Tendances

Classification using Apache SystemML by Prithviraj Sen
Classification using Apache SystemML by Prithviraj SenClassification using Apache SystemML by Prithviraj Sen
Classification using Apache SystemML by Prithviraj SenArvind Surve
 
Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplifiedNaveenkumar Muguda
 
Immutability, and how to do it in JavaScripts
Immutability, and how to do it in JavaScriptsImmutability, and how to do it in JavaScripts
Immutability, and how to do it in JavaScriptsAnton Astashov
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arraysIntro C# Book
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : ArraysGagan Deep
 
Day 1b R structures objects.pptx
Day 1b   R structures   objects.pptxDay 1b   R structures   objects.pptx
Day 1b R structures objects.pptxAdrien Melquiond
 
Matlab Graphics Tutorial
Matlab Graphics TutorialMatlab Graphics Tutorial
Matlab Graphics TutorialCheng-An Yang
 
Lesson 11 derivative of trigonometric functions
Lesson 11 derivative of trigonometric functionsLesson 11 derivative of trigonometric functions
Lesson 11 derivative of trigonometric functionsRnold Wilson
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in CSmit Parikh
 
Java notes 1 - operators control-flow
Java notes   1 - operators control-flowJava notes   1 - operators control-flow
Java notes 1 - operators control-flowMohammed Sikander
 
Day 1d R structures & objects: matrices and data frames.pptx
Day 1d   R structures & objects: matrices and data frames.pptxDay 1d   R structures & objects: matrices and data frames.pptx
Day 1d R structures & objects: matrices and data frames.pptxAdrien Melquiond
 
Building a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsBuilding a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsNicolas Hery
 
SPL 12 | Multi-dimensional Array in C
SPL 12 | Multi-dimensional Array in CSPL 12 | Multi-dimensional Array in C
SPL 12 | Multi-dimensional Array in CMohammad Imam Hossain
 
Chapter 7.3
Chapter 7.3Chapter 7.3
Chapter 7.3sotlsoc
 

Tendances (19)

2D arrays
2D arrays2D arrays
2D arrays
 
Classification using Apache SystemML by Prithviraj Sen
Classification using Apache SystemML by Prithviraj SenClassification using Apache SystemML by Prithviraj Sen
Classification using Apache SystemML by Prithviraj Sen
 
Java arrays
Java   arraysJava   arrays
Java arrays
 
Functional Programming, simplified
Functional Programming, simplifiedFunctional Programming, simplified
Functional Programming, simplified
 
Immutability, and how to do it in JavaScripts
Immutability, and how to do it in JavaScriptsImmutability, and how to do it in JavaScripts
Immutability, and how to do it in JavaScripts
 
18. Java associative arrays
18. Java associative arrays18. Java associative arrays
18. Java associative arrays
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Day 1b R structures objects.pptx
Day 1b   R structures   objects.pptxDay 1b   R structures   objects.pptx
Day 1b R structures objects.pptx
 
Matlab Graphics Tutorial
Matlab Graphics TutorialMatlab Graphics Tutorial
Matlab Graphics Tutorial
 
Lesson 11 derivative of trigonometric functions
Lesson 11 derivative of trigonometric functionsLesson 11 derivative of trigonometric functions
Lesson 11 derivative of trigonometric functions
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Intro to matlab
Intro to matlabIntro to matlab
Intro to matlab
 
Java notes 1 - operators control-flow
Java notes   1 - operators control-flowJava notes   1 - operators control-flow
Java notes 1 - operators control-flow
 
Day 1d R structures & objects: matrices and data frames.pptx
Day 1d   R structures & objects: matrices and data frames.pptxDay 1d   R structures & objects: matrices and data frames.pptx
Day 1d R structures & objects: matrices and data frames.pptx
 
Building a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsBuilding a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.js
 
SPL 12 | Multi-dimensional Array in C
SPL 12 | Multi-dimensional Array in CSPL 12 | Multi-dimensional Array in C
SPL 12 | Multi-dimensional Array in C
 
2D Array
2D Array 2D Array
2D Array
 
Chapter 7.3
Chapter 7.3Chapter 7.3
Chapter 7.3
 

En vedette

Leveraging Community Engagement for Brand Engagement, 2012, presentation
Leveraging Community Engagement for Brand Engagement, 2012, presentationLeveraging Community Engagement for Brand Engagement, 2012, presentation
Leveraging Community Engagement for Brand Engagement, 2012, presentationFlorent Renucci
 
Presentation9juin2010
Presentation9juin2010Presentation9juin2010
Presentation9juin2010phothisane
 
Joseph Bradley, Software Engineer, Databricks Inc. at MLconf SEA - 5/01/15
Joseph Bradley, Software Engineer, Databricks Inc. at MLconf SEA - 5/01/15Joseph Bradley, Software Engineer, Databricks Inc. at MLconf SEA - 5/01/15
Joseph Bradley, Software Engineer, Databricks Inc. at MLconf SEA - 5/01/15MLconf
 
Generalization of Principal Component Analysis, presentation, 2012
Generalization of Principal Component Analysis, presentation, 2012Generalization of Principal Component Analysis, presentation, 2012
Generalization of Principal Component Analysis, presentation, 2012Florent Renucci
 
Projet IPv6 Matrix / Version française intégrale
Projet IPv6 Matrix / Version française intégraleProjet IPv6 Matrix / Version française intégrale
Projet IPv6 Matrix / Version française intégraleOlivier MJ Crépin-Leblond
 
Inverse matrix pptx
Inverse matrix pptxInverse matrix pptx
Inverse matrix pptxKimguan Tan
 
Vector space classification
Vector space classificationVector space classification
Vector space classificationUjjawal
 
Chapter 4: Linear Algebraic Equations
Chapter 4: Linear Algebraic EquationsChapter 4: Linear Algebraic Equations
Chapter 4: Linear Algebraic EquationsMaria Fernanda
 
RcppEigen and SVD
RcppEigen and SVDRcppEigen and SVD
RcppEigen and SVDXiangze
 
Pourquoi les SEO regrettent (parfois) d'avoir dormi en cours de maths
Pourquoi les SEO regrettent (parfois) d'avoir dormi en cours de mathsPourquoi les SEO regrettent (parfois) d'avoir dormi en cours de maths
Pourquoi les SEO regrettent (parfois) d'avoir dormi en cours de mathsPhilippe YONNET
 
Linear vector space
Linear vector spaceLinear vector space
Linear vector spaceSafiya Amer
 
마켓컬리 마케팅채널분석 - 201603
마켓컬리 마케팅채널분석 - 201603마켓컬리 마케팅채널분석 - 201603
마켓컬리 마케팅채널분석 - 201603Hyeonseo Lee
 

En vedette (20)

Leveraging Community Engagement for Brand Engagement, 2012, presentation
Leveraging Community Engagement for Brand Engagement, 2012, presentationLeveraging Community Engagement for Brand Engagement, 2012, presentation
Leveraging Community Engagement for Brand Engagement, 2012, presentation
 
Presentation9juin2010
Presentation9juin2010Presentation9juin2010
Presentation9juin2010
 
Joseph Bradley, Software Engineer, Databricks Inc. at MLconf SEA - 5/01/15
Joseph Bradley, Software Engineer, Databricks Inc. at MLconf SEA - 5/01/15Joseph Bradley, Software Engineer, Databricks Inc. at MLconf SEA - 5/01/15
Joseph Bradley, Software Engineer, Databricks Inc. at MLconf SEA - 5/01/15
 
la reconnaissance des EFE
la reconnaissance des EFEla reconnaissance des EFE
la reconnaissance des EFE
 
space vector
space vectorspace vector
space vector
 
Generalization of Principal Component Analysis, presentation, 2012
Generalization of Principal Component Analysis, presentation, 2012Generalization of Principal Component Analysis, presentation, 2012
Generalization of Principal Component Analysis, presentation, 2012
 
Projet IPv6 Matrix / Version française intégrale
Projet IPv6 Matrix / Version française intégraleProjet IPv6 Matrix / Version française intégrale
Projet IPv6 Matrix / Version française intégrale
 
Cours add-r1-part0
Cours add-r1-part0Cours add-r1-part0
Cours add-r1-part0
 
Cours add-r1-part1
Cours add-r1-part1Cours add-r1-part1
Cours add-r1-part1
 
Inverse matrix pptx
Inverse matrix pptxInverse matrix pptx
Inverse matrix pptx
 
Vector space classification
Vector space classificationVector space classification
Vector space classification
 
Matrix algebra
Matrix algebraMatrix algebra
Matrix algebra
 
Cours add-r1-part5
Cours add-r1-part5Cours add-r1-part5
Cours add-r1-part5
 
Chapter 4: Linear Algebraic Equations
Chapter 4: Linear Algebraic EquationsChapter 4: Linear Algebraic Equations
Chapter 4: Linear Algebraic Equations
 
Systems of linear equations; matrices
Systems of linear equations; matricesSystems of linear equations; matrices
Systems of linear equations; matrices
 
RcppEigen and SVD
RcppEigen and SVDRcppEigen and SVD
RcppEigen and SVD
 
Pourquoi les SEO regrettent (parfois) d'avoir dormi en cours de maths
Pourquoi les SEO regrettent (parfois) d'avoir dormi en cours de mathsPourquoi les SEO regrettent (parfois) d'avoir dormi en cours de maths
Pourquoi les SEO regrettent (parfois) d'avoir dormi en cours de maths
 
Linear vector space
Linear vector spaceLinear vector space
Linear vector space
 
마켓컬리 마케팅채널분석 - 201603
마켓컬리 마케팅채널분석 - 201603마켓컬리 마케팅채널분석 - 201603
마켓컬리 마케팅채널분석 - 201603
 
Inverse matrix
Inverse matrixInverse matrix
Inverse matrix
 

Similaire à Tutorial matlab

Similaire à Tutorial matlab (20)

Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
Matlab_Harshal.pptx
Matlab_Harshal.pptxMatlab_Harshal.pptx
Matlab_Harshal.pptx
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Mat lab
Mat labMat lab
Mat lab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Enter The Matrix
Enter The MatrixEnter The Matrix
Enter The Matrix
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
Mbd2
Mbd2Mbd2
Mbd2
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 
Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
 
Image processing
Image processingImage processing
Image processing
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
C++ process new
C++ process newC++ process new
C++ process new
 
Lec3
Lec3Lec3
Lec3
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 

Dernier

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Tutorial matlab

  • 1. 1 Introduction to Matlab Introduction to Matlab 1. Vectors, matrices, and arithmetic 2. Plotting 3. Flow Constructs 4. Other Useful Things
  • 2. 2 Why use Matlab? • Drawbacks: Slow compared to C or Java • Advantages: Handles vector and matrices very nicely Quick plotting and analysis EXTENSIVE documentation (type ‘help’) Lots of nice functions: FFT, fuzzy logic, neural nets, numerical integration, OpenGL (!?) Vectors and Matrices • Can be run from command line or from *.m file scalar: x = 3 vector: x = [1 0 0] 2D matrix: x = [1 0 0; 0 1 0; 0 0 1] arbitrarily higher dimensions possible • Can also use matrices / vectors as elements: x = [1 2 3] y = [ x 4 5 6]
  • 3. 3 Some Standard matrices • ones(3,3) 3x3 of all ones • zeros(3,3) 3x3 of all zeros • eye(3,3) 3x3 identity • rand(3) 3x3 random elements • linspace(1,10,100) linear spacing from 1 to 10, with 100 spacings (also logspace) • x = 1:10 linear spacing from 1 to 10, counting by 1 Accessing elements • MATLAB IS NOT ZERO INDEXED! • x retrieves entire matrix x • x(1,2) retrieves element at row 1, col 2 • x(1, 5:10) retrieves row 1, columns 5 to 10 • x(1,:) retrieves row 1, all columns • Useful functions: length(x) length of vector x (cols) size(x) rows, cols of x
  • 4. 4 Matrix Operations • For matrix operations – Dimensions must agree • Scalar operations – Same as usual • Scalar / matrix mixed – Scalar + matrix = [scalar + matrix(x, y)] – Scalar * matrix = [scalar * matrix(x, y)] More Matrix Operations • The ‘.’ operator – “element by element” access • Example: – x = [1 2 3]; y = [4; 5; 6]; – x * y = 32 – x .* y = [4 10 18] • For some functions : – x ^ 2 ERROR! – x . ^2 fine
  • 5. 5 More Matrix Operations • x=1:12 • reshape(x, 3,4) • a=2*ones(3,4) • X.*a • b=[1:3;1:3;1:3;1:3] • X.*b • y=reshape(x, 4,3) • y.^b Plotting • 2D graphing plot(x,y) • Example: x = linspace(-10,10,100) y = x .^2 plot(x,y) • Also: z = x .^3 plot(x,z)
  • 6. 6 Plotting Example basis = [ [1 0]; [0 0]; [0 1]; ]'; square = [ [ 1 1] [-1 1]; [-1 -1]; [ 1 -1]; [ 1 1]; ]'; axis equal; plot( sqrt(3), sqrt(3), 'w.'); plot( -sqrt(3), -sqrt(3), 'w.'); plot( basis(1,:), basis(2,:), 'k'); plot( square(1,:), square(2,:), 'b');pause obj = S*square; plot( obj(1,:), obj(2,:), 'r');pause Plotting Examplebasis = [ [1 0]; [0 0]; [0 1]; [1 0]; ]'; square = [ [ 1 1]; [-1 1]; [-1 -1]; [ 1 -1]; [ 1 1];
  • 7. 7 More Plotting • Graphics Window – To open a new graph, type ‘figure’ • Multiple data sets: – Type ‘hold on’ to add new plot to current graph – Type ‘hold off’ to resume default mode • Make your graph beautiful: – title(‘apples over oranges’) – xtitle(‘apples’) – ytitle(‘oranges’) 3D Plotting • 3D plots – plot an outer product x = 1:10 y = 1:10 z = x’ * y mesh(x,y,z) Single quote ‘ means transpose
  • 8. 8 Flow Control • IF block if (<condition>) <body> elseif <body> end • WHILE block while (<condition>) <body> end Conditions same as C, ( ==, >=, <=) except != is ~= More Flow Control • FOR block for i = 1:10 <body> end • SWITCH statement switch <expression> case <condition>, <statement> otherwise <condition>, <statement> end
  • 9. 9 Other Language Features • Matlab language is pretty sophisticated – Functions Stored in a *.m file of the same name: function <return variable> = <function name>(<args>) <function body> – Structs • point.x = 2; point.y = 3; point.z = 4; Useful Commands • Single quote is transpose • % same as // comment in C, Java No /* block comments */ • ; suppresses printing • More: max(x) min(x) mean(x) median(x) abs(x) dot(x,y) cross(x,y) flops (flops in this session)
  • 10. 10 Useful Constants • Inf infinity • NaN Not a number (div by zero) • eps machine epsilon (precision) • ans most recent unassigned answer • pi 3.14159…. • i and j Matlab supports imaginary numbers! Programming • Wrong: for x = 1:10 for y = 1:10 foo(x,y) = 2 * bar(x,y) end end • Right: foo = 2 * bar; • Matlab is optimized for vectorization
  • 11. 11 Symbolic Maths • Symbolic mathematics can be done using Matalb: a = sqrt(sym(2)) a = 2^(1/2) th=sym('th'); rt=sym([cos(th) sin(th) 0;-sin(th) cos(th) 0;0 0 1]); rt = [ cos(th), sin(th), 0] [ -sin(th), cos(th), 0] [ 0, 0, 1] Good luck