SlideShare a Scribd company logo
1 of 28
Introduction to MATLAB
and Simulink
BY
Ms.S.R.VIDHYA
ASSISTANT PROFESSOR OF
MATHEMATICS
• “The Language of Technical Computing”
• Numerical Programming Environment
• MATLAB - MATrix LABoratory
• High-Level Interpreted Language
• Uses:
• Analyze Data
• DevelopAlgorithms
• Create Models andApplications.
• MultidisciplinaryApplications
Introduction to MATLAB and Simulink
• Acquire and Analyze Data from different sources
• Data from Measuring and Sensing Instruments
• Recorded Data (Spreadsheets, text files, images, audio files, etc)
• Analyze Data using different tools
• Develop Functions andAlgorithms
• Visualize Data in terms of graphs, plots, etc
• Simulink is used to Develop Models andApplications
• Deploy Code as StandaloneApplications
Introduction to MATLAB and Simulink
• MATLAB is a Multi-discipinary Tool
• Can be used in any Numerical ComputationApplication
• 90+ Toolboxes in multiple fields
• Mathematics(Symbolic Math, Statistics, Curve fitting, Optimization)
• Communications & Signal Processing (RF, LTE, DSP, Wavelets)
• Machine Vision (Image Processing, Computer Vision)
• Control Systems (Fuzzy Logic, Predictive Control, Neural Networks)
• Parallel Computing and Distributed Computing
• Statistics and Curve Fitting
• Computational Finance ( Financial, Econometrics, Trading, etc)
• Instrument Control, Vehicle Networks (CAN) , Aerospace
Introduction to MATLAB and Simulink
• Simulink is a Block Diagram Environment for Multidomain
simulation and Model-Based Design.
• Build, Simulate and Analyze models using Blocks.
• Connect to External Hardware (FPGA, DSP Processors,
Microprocessor, Microcontroller, etc) and run the models there
directly.
• Simscape (Physical Systems – Mechanical, Electrical, Hydraulic, etc)
• SimMechanics ( Robotics, Vehicle Suspensions, HIL system support)
• SimDriveline (1-D Driveline System Simulation)
• SimHydraulics (Hydraulic Components)
• SimRF (RF Systems)
• SimPowerSystems (Electrical Power Systems)
• SimElectronics (Motors, Drives, Sensors, Actuators, etc)
Introduction to MATLAB and Simulink
• MATLAB has optimized mathematical algorithms which
perform mathematical operations very efficiently.
• High speed of computation.
• Easy to learn and write MATLAB code.
• Tons of built-in code and freely available User-submitted code.
• Simulink uses Block approach with Drag-And-Drop.
• Easy to use and implement models.
• No hassle deployment of same model to multiple devices
Introduction to MATLAB and Simulink
Introduction to MATLAB and Simulink
• Command Window
• Type commands
• Current Directory
• View folders and m-files
• Workspace
• View program variables
• Double click on a variable
to see it in the ArrayEditor
• Command History
• View Past Commands
• Save a whole
session using
Diary
• MATLAB works primarily (almost exclusively) with matrices.
• MATLAB functions are optimized to handle matrix operations.
• MATLAB can handle upto 13-dimensional matrices.
• Loops can be vectorized for faster operations.
Introduction to MATLAB and Simulink
• Matrix is a one- or multi-dimensional array of elements.
• Elements can be numerical, variables or string elements.
• By default, MATLAB stores numbers as double precision.
• ALL data in MATLAB are viewed as matrices.
• Matrices can be:
• Created Manually by User
• Generated by MATLAB Functions
• Imported from stored databases or files
Introduction to MATLAB and Simulink
• Unlike C, MATLAB is an interpreted language. So, there is no
need for Type Declaration.
• A single variable is interpreted as 1x1 matrix.
>> a = 5
a =
5
• Arrays are represented as a series of numbers (or characters)
within square brackets, with or without a comma separating the
values.
>> b = [1 2 3 4 5] % Percentage Symbol indicates Comment
b =
1 2 3 4 5
Introduction to MATLAB and Simulink
• 2-D or Multidimensional Arrays are represented withinsquare
brackets, with the ; (semicolon) operator indicating end of a
row.
>> c = [1 2 3 ; 4 5 6 ; 7 8 9 ; 10 11 12]
c =
1 2 3
4 5 6
7 8 9
10 11 12
• c is now a 2-D array with 4 rows and 3 columns
Note : Variable names are case sensitive and can be upto 31 characters long, and have
to start with an alphabet.
Introduction to MATLAB and Simulink
• Character strings are treated as arrays too.
>> name = 'Ravi’
is the same as
>> name = [‘R’ ‘a’ ‘v’ ‘i’]
And gives the output:
name =
Ravi
• Strings and Characters are both declared within SINGLE
quotes (‘ ’)
Introduction to MATLAB and Simulink
1 2 3
4 5 6
• Unlike in case of C, MATLAB array indices start from 1.
>> d = [1 2 3 ; 4 5 6]
d =
• Addressing an element of the array is done by invoking the
element’s row and column number.
• In order to fetch the value of an element in the 2nd row and 3rd
column, we use:
>> e = d(2,3)
e =
6
Introduction to MATLAB and Simulink
• Rather than addressing single elements, we can also use
commands to address multiple elements in an array.
• The ‘:’ (colon) operator is used to address all elements in arow
or column.
• The ‘:’ operator basically tells the interpreter to addressALL
elements.
• The ‘:’ operator can also be used to indicate a range ofindices.
Introduction to MATLAB and Simulink
• Consider the earlier example: d = [1 2 3; 4 56]
•>> f = d(1, :) % Address All elements of 1st Row
f =
% Address All elements in 2nd Column
1 2 3
• >> g = d(:,2)
g =
2
5
%Address Rows from 1 to 2 and Columns from 1 to 2
>> h = d(1:2,1:2)
h =
1 2
4 5
Introduction to MATLAB and Simulink
• In some cases, we need to generate large matrices, which is difficult
to generate manually.
• There are plenty of built-in commands for this purpose!
• >> i = 0:10 % Generate numbers from 0 to 10 (Integers)
i =
0 1 2 3 4 5 6 7 8 9 10
• >> j = 0:0.2:1 % Generate numbers from 0 to 1, in steps of 0.2
j =
0 0.2000 0.4000 0.6000 0.8000 1.0000
• >> k = [1:3; 4:6;7:9] % Generate a 3x3 matrix of numbers 1 through 9
k =
1 2 3
4 5 6
7 8 9
Introduction to MATLAB and Simulink
• >> l = ones(3,2) %Generate a 3x2 matrix populated with 1s
l =
1 1
1 1
1 1
• >> m = zeros(2,4) %Generate a 2x4 matrix of 0s
m =
0 0 0 0
0 0 0 0
% Generate a 3x4 matrix of random numbers (Between 0 and 1)• >> n = rand(3,4)
n =
0.8147 0.9134 0.2785 0.9649
0.9058 0.6324 0.5469 0.1576
0.1270 0.0975 0.9575 0.9706
Introduction to MATLAB and Simulink
• x = linspace(a,b,n) % Generates n linearly-spaced values between a and b
(inclusive)
>> x = linspace(0,1,7)
x =
0 0.1667 0.3333 0.5000 0.6667 0.8333 1.0000
• x = logspace(a,b,n) % Generates n values between 10a and 10b in logarithm
space
>> x = logspace(0,1,7)
x =
1.0000 1.4678 2.1544 3.1623 4.6416 6.8129 10.0000
Introduction to MATLAB and Simulink
• Operations upon Matrices can be of two types:
• Element-wise Operation
• Matrix-wise Operation
• Common Arithmetic Operations:
• Addition (+)
• Subtraction (-)
• Multiplication (*)
• Division (/)
• Exponentiation (^)
• Matrix Inverse (inv)
• Left Division () [AB is equivalent to INV(A)*B]
• Complex Conjugate Transpose (’)
Introduction to MATLAB and Simulink
• By default, the Operators perform Matrix-wise operations.
• During Matrix-wise operations, care must be taken to avoid
dimension mismatch, specially with exponentiation, division
and multiplication.
• In case of scalar + matrix operations, matrix-wise operations are
equivalent to element-wise operations.
• ie.
Scalar + Matrix = [Scalar + Matrix(i,j)]
Scalar * Matrix = [Scalar * Matrix(i,j)]
• A dot operator(.) preceding the operator indicatesElement-wise
operations.
Introduction to MATLAB and Simulink
• Let a = [2 5; 8 1];
b = [1 2 3; 4 5 6];
c = [1 3; 5 2; 46];
% 2 x 2 Matrix
% 2 x 3 Matrix
% 3 x 2 Matrix
2 5 8
6 9 12
• Matrix Addition (or Subtraction):
>> y = b+c' % b and c have different dimensions.
y =
• Complement:
>> d = c' % d is now a 2x3 matrix
d =
1 5 4
3 2 6
Introduction to MATLAB and Simulink
• Matrix Multiplication (Or Division):
>> x = b*c % b(2x3) * c(3x2) = y (2x2). No dimension mismatch
x =
23 25
53 58
• In case of element-wise multiplication, the corresponding
elements get multiplied (Matrix Dimensions must agree)
% b(2x3)*c(2x3). No dimension mismatch)>> y = b .* d
y =
1 10 12
12 10 36
Introduction to MATLAB and Simulink
• Element-wise Exponentiation is NOT the same as Matrix-wide
exponentiation.
• Matrix Exponentiation needs square matrix as input.
>> a^2 % Matrix Exponentiation: ans = a * a
ans =
44 20
32 44
>> a.^2 % Element-wise Exponentiation: ans = a .* a
ans =
4 25
64 4
Introduction to MATLAB and Simulink
1 2 3 1 5 4
4 5 6 3 2 6
• Matrices can be concatenated just like elements in a matrix.
• Row-wise concatenation ( separated by space or commas)
 >> f = [b d]
 f =
• Column-wise concatenation (separated by semicolon)
>> g = [b ; d]
g = 1 2 3
4 5 6
1 5 4
3 2 6
Introduction to MATLAB and Simulink
% Generates a (n x n) Normally Distributed Random Matrix
% Generates a (n x n) Identity Matrix
% (n x n) Magic Matrix (Same Sum along Row, Column and Diagonal)
• >> randn(n)
• >> eye(n)
• >> magic(n)
• >> diag(A) % Extracts the elements along the primary diagonal of Matrix A
• >> blockdiag(A,B,C,..) % Generates a block diagonal matrix, with A, B, C, .. As
diagonal elements.
• >> length(x) % Calculates length of a vector x
• >> [m,n] = size(x) % Gives the [Rows,Columns] size of vectorx
• >> floor (x)
• >> ceil (x)
• >> clc
• >> clear
• >> close
• >>a = []
% Round x towards negative infinity (Floor)
% Round x towards positive infinity (Ceiling)
% Clears Command Window
% Clears the Workspace Variables
% Close Figure Windows
%Generates an Empty Matrix
Introduction to MATLAB and Simulink
Function Description
Max(x) Return largest element in a vector (each column)
Min(x) Return smallest element in a vector (each column)
Mean(x) Returns mean value of elements in vector (each column)
Std(x) Returns standard deviation of elements in vector (each column)
Median(x) Returns median of elements in vector (each column)
Sum(x) Returns sum of all values in vector (each column)
Prod(x) Returns product of elements in vector (each column)
Sort(x) Sorts values in vector in ascending order
Corr(x) Returns Pair-wise correlation coefficient
Hist(x) Plots histogram of vector x
Introduction to MATLAB and Simulink
Introduction to matlab

More Related Content

What's hot

MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1Elaf A.Saeed
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersMurshida ck
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab IntroductionDaniel Moore
 
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
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......biinoida
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operatorsLuckshay Batra
 
Basic operators in matlab
Basic operators in matlabBasic operators in matlab
Basic operators in matlabrishiteta
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopessana mateen
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithmsRajendran
 
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...Simplilearn
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Luzan Baral
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arraysAmeen San
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsİbrahim Kürce
 

What's hot (20)

MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
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
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operators
 
Basic operators in matlab
Basic operators in matlabBasic operators in matlab
Basic operators in matlab
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
Linear Algebra
Linear AlgebraLinear Algebra
Linear Algebra
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
 
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
 
History of java'
History of java'History of java'
History of java'
 
Java Notes
Java NotesJava Notes
Java Notes
 

Similar to Introduction to matlab

Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABRavikiran A
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptxBeheraA
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlabTUOS-Sam
 
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
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in spaceFaizan Shabbir
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical ComputingNaveed Rehman
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionssuser2797e4
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 

Similar to Introduction to matlab (20)

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
 
Simulation lab
Simulation labSimulation lab
Simulation lab
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Matlab
MatlabMatlab
Matlab
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
Matlab1
Matlab1Matlab1
Matlab1
 
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
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
 
An Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked ExamplesAn Introduction to MATLAB with Worked Examples
An Introduction to MATLAB with Worked Examples
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 

More from VidhyaSenthil

Abstract Algebra - Cyclic Group.pptx
Abstract Algebra - Cyclic Group.pptxAbstract Algebra - Cyclic Group.pptx
Abstract Algebra - Cyclic Group.pptxVidhyaSenthil
 
Queueing Theory.pptx
Queueing Theory.pptxQueueing Theory.pptx
Queueing Theory.pptxVidhyaSenthil
 
Branch and bound method
Branch and bound methodBranch and bound method
Branch and bound methodVidhyaSenthil
 
Applications of Mathematics
Applications of MathematicsApplications of Mathematics
Applications of MathematicsVidhyaSenthil
 
Operations research
Operations research Operations research
Operations research VidhyaSenthil
 

More from VidhyaSenthil (9)

Abstract Algebra - Cyclic Group.pptx
Abstract Algebra - Cyclic Group.pptxAbstract Algebra - Cyclic Group.pptx
Abstract Algebra - Cyclic Group.pptx
 
Queueing Theory.pptx
Queueing Theory.pptxQueueing Theory.pptx
Queueing Theory.pptx
 
Twilight.pptx
Twilight.pptxTwilight.pptx
Twilight.pptx
 
Celestial sphere
Celestial sphereCelestial sphere
Celestial sphere
 
Branch and bound method
Branch and bound methodBranch and bound method
Branch and bound method
 
Biostatistics
BiostatisticsBiostatistics
Biostatistics
 
Vector Calculus
Vector Calculus Vector Calculus
Vector Calculus
 
Applications of Mathematics
Applications of MathematicsApplications of Mathematics
Applications of Mathematics
 
Operations research
Operations research Operations research
Operations research
 

Recently uploaded

Analytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfAnalytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfSwapnil Therkar
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...jana861314
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...Sérgio Sacani
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxAleenaTreesaSaji
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
The Black hole shadow in Modified Gravity
The Black hole shadow in Modified GravityThe Black hole shadow in Modified Gravity
The Black hole shadow in Modified GravitySubhadipsau21168
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
Module 4: Mendelian Genetics and Punnett Square
Module 4:  Mendelian Genetics and Punnett SquareModule 4:  Mendelian Genetics and Punnett Square
Module 4: Mendelian Genetics and Punnett SquareIsiahStephanRadaza
 
Recombination DNA Technology (Microinjection)
Recombination DNA Technology (Microinjection)Recombination DNA Technology (Microinjection)
Recombination DNA Technology (Microinjection)Jshifa
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PPRINCE C P
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Work, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE PhysicsWork, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE Physicsvishikhakeshava1
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)DHURKADEVIBASKAR
 

Recently uploaded (20)

Analytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdfAnalytical Profile of Coleus Forskohlii | Forskolin .pdf
Analytical Profile of Coleus Forskohlii | Forskolin .pdf
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
 
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
PossibleEoarcheanRecordsoftheGeomagneticFieldPreservedintheIsuaSupracrustalBe...
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptx
 
Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
The Black hole shadow in Modified Gravity
The Black hole shadow in Modified GravityThe Black hole shadow in Modified Gravity
The Black hole shadow in Modified Gravity
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
Module 4: Mendelian Genetics and Punnett Square
Module 4:  Mendelian Genetics and Punnett SquareModule 4:  Mendelian Genetics and Punnett Square
Module 4: Mendelian Genetics and Punnett Square
 
Recombination DNA Technology (Microinjection)
Recombination DNA Technology (Microinjection)Recombination DNA Technology (Microinjection)
Recombination DNA Technology (Microinjection)
 
Artificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C PArtificial Intelligence In Microbiology by Dr. Prince C P
Artificial Intelligence In Microbiology by Dr. Prince C P
 
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Work, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE PhysicsWork, Energy and Power for class 10 ICSE Physics
Work, Energy and Power for class 10 ICSE Physics
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)
 

Introduction to matlab

  • 1. Introduction to MATLAB and Simulink BY Ms.S.R.VIDHYA ASSISTANT PROFESSOR OF MATHEMATICS
  • 2. • “The Language of Technical Computing” • Numerical Programming Environment • MATLAB - MATrix LABoratory • High-Level Interpreted Language • Uses: • Analyze Data • DevelopAlgorithms • Create Models andApplications. • MultidisciplinaryApplications Introduction to MATLAB and Simulink
  • 3. • Acquire and Analyze Data from different sources • Data from Measuring and Sensing Instruments • Recorded Data (Spreadsheets, text files, images, audio files, etc) • Analyze Data using different tools • Develop Functions andAlgorithms • Visualize Data in terms of graphs, plots, etc • Simulink is used to Develop Models andApplications • Deploy Code as StandaloneApplications Introduction to MATLAB and Simulink
  • 4. • MATLAB is a Multi-discipinary Tool • Can be used in any Numerical ComputationApplication • 90+ Toolboxes in multiple fields • Mathematics(Symbolic Math, Statistics, Curve fitting, Optimization) • Communications & Signal Processing (RF, LTE, DSP, Wavelets) • Machine Vision (Image Processing, Computer Vision) • Control Systems (Fuzzy Logic, Predictive Control, Neural Networks) • Parallel Computing and Distributed Computing • Statistics and Curve Fitting • Computational Finance ( Financial, Econometrics, Trading, etc) • Instrument Control, Vehicle Networks (CAN) , Aerospace Introduction to MATLAB and Simulink
  • 5. • Simulink is a Block Diagram Environment for Multidomain simulation and Model-Based Design. • Build, Simulate and Analyze models using Blocks. • Connect to External Hardware (FPGA, DSP Processors, Microprocessor, Microcontroller, etc) and run the models there directly. • Simscape (Physical Systems – Mechanical, Electrical, Hydraulic, etc) • SimMechanics ( Robotics, Vehicle Suspensions, HIL system support) • SimDriveline (1-D Driveline System Simulation) • SimHydraulics (Hydraulic Components) • SimRF (RF Systems) • SimPowerSystems (Electrical Power Systems) • SimElectronics (Motors, Drives, Sensors, Actuators, etc) Introduction to MATLAB and Simulink
  • 6. • MATLAB has optimized mathematical algorithms which perform mathematical operations very efficiently. • High speed of computation. • Easy to learn and write MATLAB code. • Tons of built-in code and freely available User-submitted code. • Simulink uses Block approach with Drag-And-Drop. • Easy to use and implement models. • No hassle deployment of same model to multiple devices Introduction to MATLAB and Simulink
  • 7.
  • 8. Introduction to MATLAB and Simulink • Command Window • Type commands • Current Directory • View folders and m-files • Workspace • View program variables • Double click on a variable to see it in the ArrayEditor • Command History • View Past Commands • Save a whole session using Diary
  • 9. • MATLAB works primarily (almost exclusively) with matrices. • MATLAB functions are optimized to handle matrix operations. • MATLAB can handle upto 13-dimensional matrices. • Loops can be vectorized for faster operations. Introduction to MATLAB and Simulink
  • 10. • Matrix is a one- or multi-dimensional array of elements. • Elements can be numerical, variables or string elements. • By default, MATLAB stores numbers as double precision. • ALL data in MATLAB are viewed as matrices. • Matrices can be: • Created Manually by User • Generated by MATLAB Functions • Imported from stored databases or files Introduction to MATLAB and Simulink
  • 11. • Unlike C, MATLAB is an interpreted language. So, there is no need for Type Declaration. • A single variable is interpreted as 1x1 matrix. >> a = 5 a = 5 • Arrays are represented as a series of numbers (or characters) within square brackets, with or without a comma separating the values. >> b = [1 2 3 4 5] % Percentage Symbol indicates Comment b = 1 2 3 4 5 Introduction to MATLAB and Simulink
  • 12. • 2-D or Multidimensional Arrays are represented withinsquare brackets, with the ; (semicolon) operator indicating end of a row. >> c = [1 2 3 ; 4 5 6 ; 7 8 9 ; 10 11 12] c = 1 2 3 4 5 6 7 8 9 10 11 12 • c is now a 2-D array with 4 rows and 3 columns Note : Variable names are case sensitive and can be upto 31 characters long, and have to start with an alphabet. Introduction to MATLAB and Simulink
  • 13. • Character strings are treated as arrays too. >> name = 'Ravi’ is the same as >> name = [‘R’ ‘a’ ‘v’ ‘i’] And gives the output: name = Ravi • Strings and Characters are both declared within SINGLE quotes (‘ ’) Introduction to MATLAB and Simulink
  • 14. 1 2 3 4 5 6 • Unlike in case of C, MATLAB array indices start from 1. >> d = [1 2 3 ; 4 5 6] d = • Addressing an element of the array is done by invoking the element’s row and column number. • In order to fetch the value of an element in the 2nd row and 3rd column, we use: >> e = d(2,3) e = 6 Introduction to MATLAB and Simulink
  • 15. • Rather than addressing single elements, we can also use commands to address multiple elements in an array. • The ‘:’ (colon) operator is used to address all elements in arow or column. • The ‘:’ operator basically tells the interpreter to addressALL elements. • The ‘:’ operator can also be used to indicate a range ofindices. Introduction to MATLAB and Simulink
  • 16. • Consider the earlier example: d = [1 2 3; 4 56] •>> f = d(1, :) % Address All elements of 1st Row f = % Address All elements in 2nd Column 1 2 3 • >> g = d(:,2) g = 2 5 %Address Rows from 1 to 2 and Columns from 1 to 2 >> h = d(1:2,1:2) h = 1 2 4 5 Introduction to MATLAB and Simulink
  • 17. • In some cases, we need to generate large matrices, which is difficult to generate manually. • There are plenty of built-in commands for this purpose! • >> i = 0:10 % Generate numbers from 0 to 10 (Integers) i = 0 1 2 3 4 5 6 7 8 9 10 • >> j = 0:0.2:1 % Generate numbers from 0 to 1, in steps of 0.2 j = 0 0.2000 0.4000 0.6000 0.8000 1.0000 • >> k = [1:3; 4:6;7:9] % Generate a 3x3 matrix of numbers 1 through 9 k = 1 2 3 4 5 6 7 8 9 Introduction to MATLAB and Simulink
  • 18. • >> l = ones(3,2) %Generate a 3x2 matrix populated with 1s l = 1 1 1 1 1 1 • >> m = zeros(2,4) %Generate a 2x4 matrix of 0s m = 0 0 0 0 0 0 0 0 % Generate a 3x4 matrix of random numbers (Between 0 and 1)• >> n = rand(3,4) n = 0.8147 0.9134 0.2785 0.9649 0.9058 0.6324 0.5469 0.1576 0.1270 0.0975 0.9575 0.9706 Introduction to MATLAB and Simulink
  • 19. • x = linspace(a,b,n) % Generates n linearly-spaced values between a and b (inclusive) >> x = linspace(0,1,7) x = 0 0.1667 0.3333 0.5000 0.6667 0.8333 1.0000 • x = logspace(a,b,n) % Generates n values between 10a and 10b in logarithm space >> x = logspace(0,1,7) x = 1.0000 1.4678 2.1544 3.1623 4.6416 6.8129 10.0000 Introduction to MATLAB and Simulink
  • 20. • Operations upon Matrices can be of two types: • Element-wise Operation • Matrix-wise Operation • Common Arithmetic Operations: • Addition (+) • Subtraction (-) • Multiplication (*) • Division (/) • Exponentiation (^) • Matrix Inverse (inv) • Left Division () [AB is equivalent to INV(A)*B] • Complex Conjugate Transpose (’) Introduction to MATLAB and Simulink
  • 21. • By default, the Operators perform Matrix-wise operations. • During Matrix-wise operations, care must be taken to avoid dimension mismatch, specially with exponentiation, division and multiplication. • In case of scalar + matrix operations, matrix-wise operations are equivalent to element-wise operations. • ie. Scalar + Matrix = [Scalar + Matrix(i,j)] Scalar * Matrix = [Scalar * Matrix(i,j)] • A dot operator(.) preceding the operator indicatesElement-wise operations. Introduction to MATLAB and Simulink
  • 22. • Let a = [2 5; 8 1]; b = [1 2 3; 4 5 6]; c = [1 3; 5 2; 46]; % 2 x 2 Matrix % 2 x 3 Matrix % 3 x 2 Matrix 2 5 8 6 9 12 • Matrix Addition (or Subtraction): >> y = b+c' % b and c have different dimensions. y = • Complement: >> d = c' % d is now a 2x3 matrix d = 1 5 4 3 2 6 Introduction to MATLAB and Simulink
  • 23. • Matrix Multiplication (Or Division): >> x = b*c % b(2x3) * c(3x2) = y (2x2). No dimension mismatch x = 23 25 53 58 • In case of element-wise multiplication, the corresponding elements get multiplied (Matrix Dimensions must agree) % b(2x3)*c(2x3). No dimension mismatch)>> y = b .* d y = 1 10 12 12 10 36 Introduction to MATLAB and Simulink
  • 24. • Element-wise Exponentiation is NOT the same as Matrix-wide exponentiation. • Matrix Exponentiation needs square matrix as input. >> a^2 % Matrix Exponentiation: ans = a * a ans = 44 20 32 44 >> a.^2 % Element-wise Exponentiation: ans = a .* a ans = 4 25 64 4 Introduction to MATLAB and Simulink
  • 25. 1 2 3 1 5 4 4 5 6 3 2 6 • Matrices can be concatenated just like elements in a matrix. • Row-wise concatenation ( separated by space or commas)  >> f = [b d]  f = • Column-wise concatenation (separated by semicolon) >> g = [b ; d] g = 1 2 3 4 5 6 1 5 4 3 2 6 Introduction to MATLAB and Simulink
  • 26. % Generates a (n x n) Normally Distributed Random Matrix % Generates a (n x n) Identity Matrix % (n x n) Magic Matrix (Same Sum along Row, Column and Diagonal) • >> randn(n) • >> eye(n) • >> magic(n) • >> diag(A) % Extracts the elements along the primary diagonal of Matrix A • >> blockdiag(A,B,C,..) % Generates a block diagonal matrix, with A, B, C, .. As diagonal elements. • >> length(x) % Calculates length of a vector x • >> [m,n] = size(x) % Gives the [Rows,Columns] size of vectorx • >> floor (x) • >> ceil (x) • >> clc • >> clear • >> close • >>a = [] % Round x towards negative infinity (Floor) % Round x towards positive infinity (Ceiling) % Clears Command Window % Clears the Workspace Variables % Close Figure Windows %Generates an Empty Matrix Introduction to MATLAB and Simulink
  • 27. Function Description Max(x) Return largest element in a vector (each column) Min(x) Return smallest element in a vector (each column) Mean(x) Returns mean value of elements in vector (each column) Std(x) Returns standard deviation of elements in vector (each column) Median(x) Returns median of elements in vector (each column) Sum(x) Returns sum of all values in vector (each column) Prod(x) Returns product of elements in vector (each column) Sort(x) Sorts values in vector in ascending order Corr(x) Returns Pair-wise correlation coefficient Hist(x) Plots histogram of vector x Introduction to MATLAB and Simulink