SlideShare a Scribd company logo
MIT OpenCourseWare
http://ocw.mit.edu




6.094 Introduction to MATLAB®
January (IAP) 2009




For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
6.094
Introduction to Programming in MATLAB®



   Lecture 1: Variables, Operations, and
                  Plotting




              Sourav Dey
            Danilo Šćepanović
               Ankit Patel
               Patrick Ho

                 IAP 2009
Course Layout


• Lectures (7pm-9pm)
     1:   Variables, Operations and Plotting
     2:   Visualization & Programming
     3:   Solving Equations, Fitting
     4:   Advanced Methods
Course Layout

• Problem Sets / Office Hours
       One per day, should take about 3 hours to do
       Submit doc or pdf (include pertinent code)

• Requirements for passing
       Attend all lectures
       Complete all problem sets (FAIL, Check or +)


• Prerequisites
       Basic familiarity with programming
       Basic linear algebra, differential equations, and
       probability
Outline

(1)   Getting Started
(2)   Making Variables
(3)   Manipulating Variables
(4)   Basic Plotting
Getting Started

• To get MATLAB Student Version for yourself
   » https://msca.mit.edu/cgi-bin/matlab
        Use VPN client to enable off-campus access
        Note: MIT certificates are required


• Open up MATLAB for Windows
        Through the START Menu


• On Athena
   » add matlab
   » matlab &
Current directory




Workspace


                               Command Window



     Command History



                          Courtesy of The MathWorks, Inc. Used with permission.
Customization
• File   Preferences
         Allows you personalize your MATLAB experience




                  Courtesy of The MathWorks, Inc. Used with permission.
MATLAB Basics

• MATLAB can be thought of as a super-powerful
  graphing calculator
         Remember the TI-83 from calculus?
         With many more buttons (built-in functions)


• In addition it is a programming language
         MATLAB is an interpreted language, like
         Scheme
         Commands executed line by line
Conversing with MATLAB

• who
         MATLAB replies with the variables in your workspace


• what
         MATLAB replies with the current directory and
         MATLAB files in the directory

• why

• help
         The most important function for learning MATLAB on
         your own
         More on help later
Outline

(1)   Getting Started
(2)   Making Variables
(3)   Manipulating Variables
(4)   Basic Plotting
Variable Types

• MATLAB is a weakly typed language
       No need to initialize variables!

• MATLAB supports various types, the most often used are
   » 3.84
        64-bit double (default)
   » ‘a’
        16-bit char

• Most variables you’ll deal with will be arrays or matrices of
  doubles or chars

• Other types are also supported: complex, symbolic, 16-bit
  and 8 bit integers, etc.
Naming variables

• To create a variable, simply assign a value to a name:
   » var1=3.14
   » myString=‘hello world’

• Variable names
         first character must be a LETTER
         after that, any combination of letters, numbers and _
         CASE SENSITIVE! (var1 is different from Var1)


• Built-in variables
         i and j can be used to indicate complex numbers
         pi has the value 3.1415926…
         ans stores the last unassigned value (like on a calculator)
         Inf and -Inf are positive and negative infinity
         NaN represents ‘Not a Number’
Hello World

• Here are several flavors of Hello World to introduce MATLAB

• MATLAB will display strings automatically
   » ‘Hello 6.094’

• To remove “ans =“, use disp()
   » disp('Hello 6.094')

• sprintf() allows you to mix strings with variables
   » class=6.094;
   » disp(sprintf('Hello %g', class))
        The format is C-syntax
Scalars


• A variable can be given a value explicitly
   » a = 10
         shows up in workspace!

• Or as a function of explicit values and existing variables
   » c = 1.3*45-2*a

• To suppress output, end the line with a semicolon
   » cooldude = 13/3;
Arrays

• Like other programming languages, arrays are an
  important part of MATLAB
• Two types of arrays

      (1) matrix of numbers (either double or complex)

      (2) cell array of objects (more advanced data structure)


               MATLAB makes vectors easy!
                    That’s its power!
Row Vectors

• Row vector: comma or space separated values between
  brackets
   » row = [1 2 5.4 -6.6];
   » row = [1, 2, 5.4, -6.6];

• Command window:




• Workspace:



                  Courtesy of The MathWorks, Inc. Used with permission.
Column Vectors

• Column vector: semicolon separated values between
  brackets
   » column = [4;2;7;4];

• Command window:




• Workspace:



                   Courtesy of The MathWorks, Inc. Used with permission.
Matrices

• Make matrices like vectors

                                   ⎡1 2⎤
• Element by element             a=⎢
   » a= [1 2;3 4];                 ⎣3 4⎥
                                       ⎦

• By concatenating vectors or matrices (dimension matters)
   » a = [1 2];
   » b = [3 4];
   » c = [5;6];

   » d = [a;b];
   » e = [d c];
   » f = [[e e];[a b a]];
save/clear/load
•   Use save to save variables to a file
     » save myfile a b
           saves variables a and b to the file myfile.mat
           myfile.mat file in the current directory
           Default working directory is
     » MATLABwork
           Create own folder and change working directory to it
     » MyDocuments6.094day1


•   Use clear to remove variables from environment
     » clear a b
           look at workspace, the variables a and b are gone

•   Use load to load variable bindings into the environment
     » load myfile
           look at workspace, the variables a and b are back

•   Can do the same for entire environment
     » save myenv; clear all; load myenv;
Exercise: Variables

• Do the following 5 things:
        Create the variable r as a row vector with values 1 4
        7 10 13
        Create the variable c as a column vector with values
        13 10 7 4 1
        Save these two variables to file varEx
        clear the workspace
        load the two variables you just created

   »   r=[1 4 7 10 13];
   »   c=[13; 10; 7; 4; 1];
   »   save varEx r c
   »   clear r c
   »   load varEx
Outline

(1)   Getting Started
(2)   Making Variables
(3)   Manipulating Variables
(4)   Basic Plotting
Basic Scalar Operations
• Arithmetic operations (+,-,*,/)
   » 7/45
   » (1+i)*(2+i)
   » 1 / 0
   » 0 / 0

• Exponentiation (^)
   » 4^2
   » (3+4*j)^2

• Complicated expressions, use parentheses
   » ((2+3)*3)^0.1

• Multiplication is NOT implicit given parentheses
   » 3(1+0.7) gives an error

• To clear cluttered command window
   » Clc
Built-in Functions

• MATLAB has an enormous library of built-in functions

• Call using parentheses – passing parameter to function
   » sqrt(2)
   » log(2), log10(0.23)
   » cos(1.2), atan(-.8)
   » exp(2+4*i)
   » round(1.4), floor(3.3), ceil(4.23)
   » angle(i); abs(1+i);
Help/Docs

• To get info on how to use a function:
   » help sin
        Help contains related functions
• To get a nicer version of help with examples and easy-to-
  read descriptions:
   » doc sin

• To search for a function by specifying keywords:
   » doc + Search tab
   » lookfor hyperbolic


               One-word description of what
               you're looking for
Exercise: Scalars

• Verify that e^(i*x) = cos(x) + i*sin(x) for a few values of x.

   »   x = pi/3;
   »   a = exp(i*x)
   »   b = cos(x)+ i*sin(x)
   »   a-b
size & length

• You can tell the difference between a row and a column
  vector by:
        Looking in the workspace
        Displaying the variable in the command window
        Using the size function




• To get a vector's length, use the length function
transpose

• The transpose operators turns a column vector into a row
  vector and vice versa
   » a = [1 2 3 4]
   » transpose(a)

• Can use dot-apostrophe as short-cut
   » a.'

• The apostrophe gives the Hermitian-transpose, i.e.
  transposes and conjugates all complex numbers
   » a = [1+j 2+3*j]
   » a'
   » a.'
• For vectors of real numbers .' and ' give same result
Addition and Subtraction

• Addition and subtraction are element-wise; sizes must
  match (unless one is a scalar):
           [12 3    32 −11]      ⎡ 12 ⎤ ⎡ 3 ⎤ ⎡ 9 ⎤
                                 ⎢ 1 ⎥ ⎢ −1⎥ ⎢ 2 ⎥
         + [ 2 11   −30 32]      ⎢     ⎥−⎢ ⎥ = ⎢    ⎥
                                 ⎢ −10 ⎥ ⎢13 ⎥ ⎢ −23⎥
        = [14 14      2 21]      ⎢     ⎥ ⎢ ⎥ ⎢      ⎥
                                 ⎣  0 ⎦ ⎣33⎦ ⎣ −33⎦

• The following would give an error
   » c = row + column
• Use the transpose to make sizes compatible
   » c = row’ + column
   » c = row + column’
• Can sum up or multiply elements of vector
   » s=sum(row);
   » p=prod(row);
Element-Wise Functions

• All the functions that work on scalars also work on vectors
   » t = [1 2 3];
   » f = exp(t);
         is the same as
   » f = [exp(1) exp(2) exp(3)];

• If in doubt, check a function’s help file to see if it handles
  vectors elementwise

• Operators (* / ^) have two modes of operation
         element-wise
         standard
Operators: element-wise

• To do element-wise operations, use the dot. BOTH
  dimensions must match (unless one is scalar)!
   » a=[1 2 3];b=[4;2;1];
   » a.*b, a./b, a.^b      all errors
   » a.*b’, a./b’, a.^(b’)       all valid

              ⎡ 4⎤                       ⎡1 1 1 ⎤ ⎡1 2 3⎤ ⎡ 1 2 3⎤
                                         ⎢ 2 2 2 ⎥ .* ⎢1 2 3⎥ = ⎢ 2 4 6 ⎥
 [1 2 3] .* ⎢ 2⎥ = ERROR
              ⎢ ⎥                        ⎢       ⎥ ⎢             ⎥ ⎢       ⎥
              ⎢1 ⎥
              ⎣ ⎦                        ⎢ 3 3 3 ⎥ ⎢1 2 3⎥ ⎢ 3 6 9 ⎥
                                         ⎣       ⎦ ⎣             ⎦ ⎣       ⎦
     ⎡1 ⎤ ⎡ 4⎤ ⎡ 4⎤                                  3 × 3.* 3 × 3 = 3 × 3
     ⎢ 2 ⎥ .* ⎢ 2 ⎥ = ⎢ 4 ⎥
     ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
     ⎢ 3⎥ ⎢1 ⎥ ⎢ 3⎥
     ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
                              ⎡1 2 ⎤        ⎡12 22 ⎤
      3 ×1.* 3 ×1 = 3 × 1     ⎢3 4 ⎥ .^ 2 = ⎢ 2    ⎥
                              ⎣    ⎦        ⎣ 3 42 ⎦
                              Can be any dimension
Operators: standard

    • Multiplication can be done in a standard way or element-wise
    • Standard multiplication (*) is either a dot-product or an outer-
      product
                 Remember from linear algebra: inner dimensions must MATCH!!
    • Standard exponentiation (^) implicitly uses *
                 Can only be done on square matrices or scalars
    • Left and right division (/ ) is same as multiplying by inverse
             Our recommendation: just multiply by inverse (more on this
             later)


          ⎡ 4⎤           ⎡1 2 ⎤     ⎡1 2 ⎤ ⎡1 2 ⎤       ⎡1 1 1⎤ ⎡1 2 3⎤ ⎡3 6 9 ⎤
[1 2 3]* ⎢ 2⎥ = 11
          ⎢ ⎥
                         ⎢3 4 ⎥
                         ⎣    ⎦
                                ^2=⎢       ⎥ * ⎢3 4 ⎥
                                    ⎣3 4 ⎦ ⎣        ⎦
                                                        ⎢2 2 2⎥ * ⎢1 2 3⎥ = ⎢6 12 18 ⎥
                                                        ⎢     ⎥ ⎢            ⎥ ⎢       ⎥
          ⎢1 ⎥
          ⎣ ⎦            Must be square to do powers    ⎢3 3 3⎥ ⎢1 2 3⎥ ⎢9 18 27⎥
                                                        ⎣     ⎦ ⎣            ⎦ ⎣       ⎦
    1× 3* 3 ×1 = 1× 1                                             3 × 3* 3 × 3 = 3 × 3
Exercise: Vector Operations

• Find the inner product between [1 2 3] and [3 5 4]
   » a=[1 2 3]*[3 5 4]’

• Multiply the same two vectors element-wise
   » b=[1 2 3].*[3 5 4]

• Calculate the natural log of each element of the resulting
  vector
   » c=log(b)
Automatic Initialization

• Initialize a vector of ones, zeros, or random numbers
   » o=ones(1,10)
        row vector with 10 elements, all 1
   » z=zeros(23,1)
        column vector with 23 elements, all 0
   » r=rand(1,45)
        row vector with 45 elements (uniform [0,1])
   » n=nan(1,69)
        row vector of NaNs (useful for representing uninitialized
        variables)
            The general function call is:
                 var=zeros(M,N);


            Number of rows       Number of columns
Automatic Initialization

• To initialize a linear vector of values use linspace
   » a=linspace(0,10,5)
         starts at 0, ends at 10 (inclusive), 5 values


• Can also use colon operator (:)
   » b=0:2:10
         starts at 0, increments by 2, and ends at or before 10
         increment can be decimal or negative
   » c=1:5
         if increment isn’t specified, default is 1


• To initialize logarithmically spaced values use logspace
         similar to linspace
Exercise: Vector Functions

• Make a vector that has 10,000 samples of
  f(x) = e^{-x}*cos(x), for x between 0 and 10.

   » x = linspace(0,10,10000);
   » f = exp(-x).*cos(x);
Vector Indexing

• MATLAB indexing starts with 1, not 0
        We will not respond to any emails where this is the
        problem.
• a(n) returns the nth element

                           [13   5 9 10]

                    a(1)    a(2)   a(3)    a(4)


• The index argument can be a vector. In this case, each
  element is looked up individually, and returned as a vector
  of the same size as the index vector.
   » x=[12 13 5 8];
   » a=x(2:3);                     a=[13 5];
   » b=x(1:end-1);                 b=[12 13 5];
Matrix Indexing

• Matrices can be indexed in two ways
            using subscripts (row and column)
            using linear indices (as if matrix is a vector)
• Matrix indexing: subscripts or linear indices



   b(1,1)      ⎡14 33⎤     b(1,2)       b(1)       ⎡14 33⎤    b(3)
   b(2,1)
               ⎢9 8⎥       b(2,2)       b(2)
                                                   ⎢9 8⎥      b(4)
               ⎣     ⎦                             ⎣     ⎦

• Picking submatrices
   » A = rand(5) % shorthand for 5x5 matrix
   » A(1:3,1:2) % specify contiguous submatrix
   » A([1 5 3], [1 4]) % specify rows and columns
Advanced Indexing 1

• The index argument can be a matrix. In this case, each
  element is looked up individually, and returned as a matrix
  of the same size as the index matrix.

   » a=[-1 10 3 -2];                   ⎡ −1 10 −2 ⎤
                                     b=⎢          ⎥
   » b=a([1 2 4;3 4 2]);               ⎣ 3 −2 10 ⎦

• To select rows or columns of a matrix, use the :

                     ⎡12 5 ⎤
                   c=⎢
                     ⎣ −2 13⎥
                            ⎦
   » d=c(1,:);                   d=[12 5];
   » e=c(:,2);                   e=[5;13];
   » c(2,:)=[3 6];     %replaces second row of c
Advanced Indexing 2

• MATLAB contains functions to help you find desired values
  within a vector or matrix
   » vec = [1 5 3 9 7]
• To get the minimum value and its index:
   » [minVal,minInd] = min(vec);
• To get the maximum value and its index:
   » [maxVal,maxInd] = max(vec);
• To find any the indices of specific values or ranges
   » ind = find(vec == 9);
   » ind = find(vec > 2 & vec < 6);
         find expressions can be very complex, more on this later
• To convert between subscripts and indices, use ind2sub,
  and sub2ind. Look up help to see how to use them.
Exercise: Vector Indexing
• Evaluate a sine wave at 1,000 points between 0 and 2*pi.
• What’s the value at
          Index 55
          Indices 100 through 110
•   Find the index of
          the minimum value,
          the maximum value, and
          values between -0.001 and 0.001


    »   x = linspace(0,2*pi,1000);
    »   y=sin(x);
    »   y(55)
    »   y(100:110)
    »   [minVal,minInd]=min(y)
    »   [maxVal,maxInd]=max(y)
    »   inds=find(y>-0.001 & y<0.001)
BONUS Exercise: Matrices

• Make a 3x100 matrix of zeros, and a vector x that has 100 values
  between 0 and 10
   » mat=zeros(3,100);
   » x=linspace(0,10,100);

• Replace the first row of the matrix with cos(x)
   » mat(1,:)=cos(x);

• Replace the second row of the matrix with log((x+2)^2)
   » mat(2,:)=log((x+2).^2);

• Replace the third row of the matrix with a random vector of the
  correct size
   » mat(3,:)=rand(1,100);
• Use the sum function to compute row and column sums of mat
  (see help)
   » rs = sum(mat,2);
   » cs = sum(mat); % default dimension is 1
Outline

(1)   Getting Started
(2)   Making Variables
(3)   Manipulating Variables
(4)   Basic Plotting
Plotting Vectors

• Example
   » x=linspace(0,4*pi,10);
   » y=sin(x);

• Plot values against their index
   » plot(y);
• Usually we want to plot y versus x
   » plot(x,y);

              MATLAB makes visualizing data
                     fun and easy!
What does plot do?
  • plot generates dots at each (x,y) pair and then connects the dots
    with a line
  • To make plot of a function look smoother, evaluate at more points
     » x=linspace(0,4*pi,1000);
     » plot(x,sin(x));
  • x and y vectors must be same size or else you’ll get an error
     » plot([1 2], [1 2 3])
                 error!!

                 1                                                          1



10 x values:   0.8

               0.6
                                                         1000 x values:
                                                                          0.8

                                                                          0.6

               0.4                                                        0.4

               0.2                                                        0.2

                 0                                                          0

               -0.2                                                       -0.2

               -0.4                                                       -0.4

               -0.6                                                       -0.6

               -0.8                                                       -0.8

                -1                                                         -1
                      0   2   4   6   8   10   12   14                           0   2   4   6   8   10   12   14
Plot Options

• Can change the line color, marker style, and line style by
  adding a string argument
   » plot(x,y,’k.-’);

          color    marker   line-style

• Can plot without connecting the dots by omitting line style
  argument
   » plot(x,y,’.’)

• Look at help plot for a full list of colors, markers, and
  linestyles
Other Useful plot Commands

• Much more on this in Lecture 2, for now some simple
  commands

• To   plot two lines on the same graph
   »   hold on;
• To   plot on a new figure
   »   figure;
   »   plot(x,y);

• Play with the figure GUI to learn more
          add axis labels
          add a title
          add a grid
          zoom in/zoom out
Exercise: Plotting

• Plot f(x) = e^x*cos(x) on the interval x = [0 10]. Use a red
  solid line with a suitable number of points to get a good
  resolution.

   » x=0:.01:10;
   » plot(x,exp(x).*cos(x),’r’);
End of Lecture 1

(1)   Getting Started
(2)   Making Variables
(3)   Manipulating Variables
(4)   Basic Plotting


       Hope that wasn’t too much!!

More Related Content

What's hot

Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
Ameen San
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
Divyanshu Rasauria
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
Respa Peter
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
krajeshk1980
 
Tsp branch and-bound
Tsp branch and-boundTsp branch and-bound
Tsp branch and-bound
Saravanan Natarajan
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
aman gupta
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
chestialtaff
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operators
Luckshay Batra
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
Mahzad Zahedi
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
Mahdi Esmailoghli
 
Matrix Manipulation in Matlab
Matrix Manipulation in MatlabMatrix Manipulation in Matlab
Matrix Manipulation in Matlab
Mohamed Loey
 
Ethernet
EthernetEthernet
Ethernet
Jaya Yadav
 
MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
Dr. Krishna Mohbey
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
Maulik Borsaniya
 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
Infinity Tech Solutions
 
Gnu octave
Gnu octave Gnu octave
Gnu octave
Milad Nourizade
 
Basic operators in matlab
Basic operators in matlabBasic operators in matlab
Basic operators in matlab
rishiteta
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Satish Gummadi
 
Parse Tree
Parse TreeParse Tree
Parse Tree
A. S. M. Shafi
 

What's hot (20)

Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Tsp branch and-bound
Tsp branch and-boundTsp branch and-bound
Tsp branch and-bound
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operators
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
 
Matrix Manipulation in Matlab
Matrix Manipulation in MatlabMatrix Manipulation in Matlab
Matrix Manipulation in Matlab
 
Ethernet
EthernetEthernet
Ethernet
 
MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
 
Gnu octave
Gnu octave Gnu octave
Gnu octave
 
Basic operators in matlab
Basic operators in matlabBasic operators in matlab
Basic operators in matlab
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Parse Tree
Parse TreeParse Tree
Parse Tree
 

Viewers also liked

A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
Shameer Ahmed Koya
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLAB
Shameer Ahmed Koya
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2
Shameer Ahmed Koya
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
Shameer Ahmed Koya
 
User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1
Shameer Ahmed Koya
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
Reduction of multiple subsystem [compatibility mode]
Reduction of multiple subsystem [compatibility mode]Reduction of multiple subsystem [compatibility mode]
Reduction of multiple subsystem [compatibility mode]azroyyazid
 
MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2
Shameer Ahmed Koya
 
Polynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLABPolynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLAB
Shameer Ahmed Koya
 
MS Sql Server: Reporting basics
MS Sql Server: Reporting basicsMS Sql Server: Reporting basics
MS Sql Server: Reporting basics
DataminingTools Inc
 
Matlab Organizing Data
Matlab Organizing DataMatlab Organizing Data
Matlab Organizing Data
DataminingTools Inc
 
block diagram representation of control systems
block diagram representation of  control systemsblock diagram representation of  control systems
block diagram representation of control systemsAhmed Elmorsy
 

Viewers also liked (14)

A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLAB
 
User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2User Defined Functions in MATLAB part 2
User Defined Functions in MATLAB part 2
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
 
User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1User defined Functions in MATLAB Part 1
User defined Functions in MATLAB Part 1
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
 
Reduction of multiple subsystem [compatibility mode]
Reduction of multiple subsystem [compatibility mode]Reduction of multiple subsystem [compatibility mode]
Reduction of multiple subsystem [compatibility mode]
 
MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2MATLAB Programming - Loop Control Part 2
MATLAB Programming - Loop Control Part 2
 
Polynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLABPolynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLAB
 
MS Sql Server: Reporting basics
MS Sql Server: Reporting basicsMS Sql Server: Reporting basics
MS Sql Server: Reporting basics
 
Matlab Organizing Data
Matlab Organizing DataMatlab Organizing Data
Matlab Organizing Data
 
bobok
bobokbobok
bobok
 
block diagram representation of control systems
block diagram representation of  control systemsblock diagram representation of  control systems
block diagram representation of control systems
 

Similar to Matlab lec1

Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
Smee Kaem Chann
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
Tribhuwan Pant
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
محمدعبد الحى
 
Matlab pt1
Matlab pt1Matlab pt1
Matlab pt1
Austin Baird
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
Ravibabu Kancharla
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
AkashSingh728626
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
Vinay Kumar
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
RaviMuthamala1
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
aboma2hawi
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
Faizan Shabbir
 
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
MahuaPal6
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Ravikiran A
 
Programming in python
Programming in pythonProgramming in python
Programming in python
Ivan Rojas
 
Introduction to programming in MATLAB
Introduction to programming in MATLABIntroduction to programming in MATLAB
Introduction to programming in MATLAB
mustafa_92
 
MATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptMATLAB_CIS601-03.ppt
MATLAB_CIS601-03.ppt
aboma2hawi
 
Mbd dd
Mbd ddMbd dd
Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
ssuserff72e4
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 

Similar to Matlab lec1 (20)

Lecture 01 variables scripts and operations
Lecture 01   variables scripts and operationsLecture 01   variables scripts and operations
Lecture 01 variables scripts and operations
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
Matlab pt1
Matlab pt1Matlab pt1
Matlab pt1
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
Mat lab workshop
Mat lab workshopMat lab workshop
Mat lab workshop
 
Mit6 094 iap10_lec05
Mit6 094 iap10_lec05Mit6 094 iap10_lec05
Mit6 094 iap10_lec05
 
Matlab Tutorial.ppt
Matlab Tutorial.pptMatlab Tutorial.ppt
Matlab Tutorial.ppt
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
 
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
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Programming in python
Programming in pythonProgramming in python
Programming in python
 
Introduction to programming in MATLAB
Introduction to programming in MATLABIntroduction to programming in MATLAB
Introduction to programming in MATLAB
 
MATLAB_CIS601-03.ppt
MATLAB_CIS601-03.pptMATLAB_CIS601-03.ppt
MATLAB_CIS601-03.ppt
 
Mbd dd
Mbd ddMbd dd
Mbd dd
 
Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 

More from Amba Research

Case Econ08 Ppt 07
Case Econ08 Ppt 07Case Econ08 Ppt 07
Case Econ08 Ppt 07
Amba Research
 
Case Econ08 Ppt 06
Case Econ08 Ppt 06Case Econ08 Ppt 06
Case Econ08 Ppt 06
Amba Research
 
Case Econ08 Ppt 05
Case Econ08 Ppt 05Case Econ08 Ppt 05
Case Econ08 Ppt 05
Amba Research
 
Case Econ08 Ppt 04
Case Econ08 Ppt 04Case Econ08 Ppt 04
Case Econ08 Ppt 04
Amba Research
 
Case Econ08 Ppt 03
Case Econ08 Ppt 03Case Econ08 Ppt 03
Case Econ08 Ppt 03
Amba Research
 
Case Econ08 Ppt 02
Case Econ08 Ppt 02Case Econ08 Ppt 02
Case Econ08 Ppt 02
Amba Research
 
Case Econ08 Ppt 01
Case Econ08 Ppt 01Case Econ08 Ppt 01
Case Econ08 Ppt 01
Amba Research
 

More from Amba Research (20)

Case Econ08 Ppt 16
Case Econ08 Ppt 16Case Econ08 Ppt 16
Case Econ08 Ppt 16
 
Case Econ08 Ppt 08
Case Econ08 Ppt 08Case Econ08 Ppt 08
Case Econ08 Ppt 08
 
Case Econ08 Ppt 11
Case Econ08 Ppt 11Case Econ08 Ppt 11
Case Econ08 Ppt 11
 
Case Econ08 Ppt 14
Case Econ08 Ppt 14Case Econ08 Ppt 14
Case Econ08 Ppt 14
 
Case Econ08 Ppt 12
Case Econ08 Ppt 12Case Econ08 Ppt 12
Case Econ08 Ppt 12
 
Case Econ08 Ppt 10
Case Econ08 Ppt 10Case Econ08 Ppt 10
Case Econ08 Ppt 10
 
Case Econ08 Ppt 15
Case Econ08 Ppt 15Case Econ08 Ppt 15
Case Econ08 Ppt 15
 
Case Econ08 Ppt 13
Case Econ08 Ppt 13Case Econ08 Ppt 13
Case Econ08 Ppt 13
 
Case Econ08 Ppt 07
Case Econ08 Ppt 07Case Econ08 Ppt 07
Case Econ08 Ppt 07
 
Case Econ08 Ppt 06
Case Econ08 Ppt 06Case Econ08 Ppt 06
Case Econ08 Ppt 06
 
Case Econ08 Ppt 05
Case Econ08 Ppt 05Case Econ08 Ppt 05
Case Econ08 Ppt 05
 
Case Econ08 Ppt 04
Case Econ08 Ppt 04Case Econ08 Ppt 04
Case Econ08 Ppt 04
 
Case Econ08 Ppt 03
Case Econ08 Ppt 03Case Econ08 Ppt 03
Case Econ08 Ppt 03
 
Case Econ08 Ppt 02
Case Econ08 Ppt 02Case Econ08 Ppt 02
Case Econ08 Ppt 02
 
Case Econ08 Ppt 01
Case Econ08 Ppt 01Case Econ08 Ppt 01
Case Econ08 Ppt 01
 
pyton Notes9
pyton Notes9pyton Notes9
pyton Notes9
 
Notes8
Notes8Notes8
Notes8
 
Notes7
Notes7Notes7
Notes7
 
pyton Notes6
 pyton Notes6 pyton Notes6
pyton Notes6
 
pyton Notes1
pyton Notes1pyton Notes1
pyton Notes1
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 

Matlab lec1

  • 1. MIT OpenCourseWare http://ocw.mit.edu 6.094 Introduction to MATLAB® January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
  • 2. 6.094 Introduction to Programming in MATLAB® Lecture 1: Variables, Operations, and Plotting Sourav Dey Danilo Šćepanović Ankit Patel Patrick Ho IAP 2009
  • 3. Course Layout • Lectures (7pm-9pm) 1: Variables, Operations and Plotting 2: Visualization & Programming 3: Solving Equations, Fitting 4: Advanced Methods
  • 4. Course Layout • Problem Sets / Office Hours One per day, should take about 3 hours to do Submit doc or pdf (include pertinent code) • Requirements for passing Attend all lectures Complete all problem sets (FAIL, Check or +) • Prerequisites Basic familiarity with programming Basic linear algebra, differential equations, and probability
  • 5. Outline (1) Getting Started (2) Making Variables (3) Manipulating Variables (4) Basic Plotting
  • 6. Getting Started • To get MATLAB Student Version for yourself » https://msca.mit.edu/cgi-bin/matlab Use VPN client to enable off-campus access Note: MIT certificates are required • Open up MATLAB for Windows Through the START Menu • On Athena » add matlab » matlab &
  • 7. Current directory Workspace Command Window Command History Courtesy of The MathWorks, Inc. Used with permission.
  • 8. Customization • File Preferences Allows you personalize your MATLAB experience Courtesy of The MathWorks, Inc. Used with permission.
  • 9. MATLAB Basics • MATLAB can be thought of as a super-powerful graphing calculator Remember the TI-83 from calculus? With many more buttons (built-in functions) • In addition it is a programming language MATLAB is an interpreted language, like Scheme Commands executed line by line
  • 10. Conversing with MATLAB • who MATLAB replies with the variables in your workspace • what MATLAB replies with the current directory and MATLAB files in the directory • why • help The most important function for learning MATLAB on your own More on help later
  • 11. Outline (1) Getting Started (2) Making Variables (3) Manipulating Variables (4) Basic Plotting
  • 12. Variable Types • MATLAB is a weakly typed language No need to initialize variables! • MATLAB supports various types, the most often used are » 3.84 64-bit double (default) » ‘a’ 16-bit char • Most variables you’ll deal with will be arrays or matrices of doubles or chars • Other types are also supported: complex, symbolic, 16-bit and 8 bit integers, etc.
  • 13. Naming variables • To create a variable, simply assign a value to a name: » var1=3.14 » myString=‘hello world’ • Variable names first character must be a LETTER after that, any combination of letters, numbers and _ CASE SENSITIVE! (var1 is different from Var1) • Built-in variables i and j can be used to indicate complex numbers pi has the value 3.1415926… ans stores the last unassigned value (like on a calculator) Inf and -Inf are positive and negative infinity NaN represents ‘Not a Number’
  • 14. Hello World • Here are several flavors of Hello World to introduce MATLAB • MATLAB will display strings automatically » ‘Hello 6.094’ • To remove “ans =“, use disp() » disp('Hello 6.094') • sprintf() allows you to mix strings with variables » class=6.094; » disp(sprintf('Hello %g', class)) The format is C-syntax
  • 15. Scalars • A variable can be given a value explicitly » a = 10 shows up in workspace! • Or as a function of explicit values and existing variables » c = 1.3*45-2*a • To suppress output, end the line with a semicolon » cooldude = 13/3;
  • 16. Arrays • Like other programming languages, arrays are an important part of MATLAB • Two types of arrays (1) matrix of numbers (either double or complex) (2) cell array of objects (more advanced data structure) MATLAB makes vectors easy! That’s its power!
  • 17. Row Vectors • Row vector: comma or space separated values between brackets » row = [1 2 5.4 -6.6]; » row = [1, 2, 5.4, -6.6]; • Command window: • Workspace: Courtesy of The MathWorks, Inc. Used with permission.
  • 18. Column Vectors • Column vector: semicolon separated values between brackets » column = [4;2;7;4]; • Command window: • Workspace: Courtesy of The MathWorks, Inc. Used with permission.
  • 19. Matrices • Make matrices like vectors ⎡1 2⎤ • Element by element a=⎢ » a= [1 2;3 4]; ⎣3 4⎥ ⎦ • By concatenating vectors or matrices (dimension matters) » a = [1 2]; » b = [3 4]; » c = [5;6]; » d = [a;b]; » e = [d c]; » f = [[e e];[a b a]];
  • 20. save/clear/load • Use save to save variables to a file » save myfile a b saves variables a and b to the file myfile.mat myfile.mat file in the current directory Default working directory is » MATLABwork Create own folder and change working directory to it » MyDocuments6.094day1 • Use clear to remove variables from environment » clear a b look at workspace, the variables a and b are gone • Use load to load variable bindings into the environment » load myfile look at workspace, the variables a and b are back • Can do the same for entire environment » save myenv; clear all; load myenv;
  • 21. Exercise: Variables • Do the following 5 things: Create the variable r as a row vector with values 1 4 7 10 13 Create the variable c as a column vector with values 13 10 7 4 1 Save these two variables to file varEx clear the workspace load the two variables you just created » r=[1 4 7 10 13]; » c=[13; 10; 7; 4; 1]; » save varEx r c » clear r c » load varEx
  • 22. Outline (1) Getting Started (2) Making Variables (3) Manipulating Variables (4) Basic Plotting
  • 23. Basic Scalar Operations • Arithmetic operations (+,-,*,/) » 7/45 » (1+i)*(2+i) » 1 / 0 » 0 / 0 • Exponentiation (^) » 4^2 » (3+4*j)^2 • Complicated expressions, use parentheses » ((2+3)*3)^0.1 • Multiplication is NOT implicit given parentheses » 3(1+0.7) gives an error • To clear cluttered command window » Clc
  • 24. Built-in Functions • MATLAB has an enormous library of built-in functions • Call using parentheses – passing parameter to function » sqrt(2) » log(2), log10(0.23) » cos(1.2), atan(-.8) » exp(2+4*i) » round(1.4), floor(3.3), ceil(4.23) » angle(i); abs(1+i);
  • 25. Help/Docs • To get info on how to use a function: » help sin Help contains related functions • To get a nicer version of help with examples and easy-to- read descriptions: » doc sin • To search for a function by specifying keywords: » doc + Search tab » lookfor hyperbolic One-word description of what you're looking for
  • 26. Exercise: Scalars • Verify that e^(i*x) = cos(x) + i*sin(x) for a few values of x. » x = pi/3; » a = exp(i*x) » b = cos(x)+ i*sin(x) » a-b
  • 27. size & length • You can tell the difference between a row and a column vector by: Looking in the workspace Displaying the variable in the command window Using the size function • To get a vector's length, use the length function
  • 28. transpose • The transpose operators turns a column vector into a row vector and vice versa » a = [1 2 3 4] » transpose(a) • Can use dot-apostrophe as short-cut » a.' • The apostrophe gives the Hermitian-transpose, i.e. transposes and conjugates all complex numbers » a = [1+j 2+3*j] » a' » a.' • For vectors of real numbers .' and ' give same result
  • 29. Addition and Subtraction • Addition and subtraction are element-wise; sizes must match (unless one is a scalar): [12 3 32 −11] ⎡ 12 ⎤ ⎡ 3 ⎤ ⎡ 9 ⎤ ⎢ 1 ⎥ ⎢ −1⎥ ⎢ 2 ⎥ + [ 2 11 −30 32] ⎢ ⎥−⎢ ⎥ = ⎢ ⎥ ⎢ −10 ⎥ ⎢13 ⎥ ⎢ −23⎥ = [14 14 2 21] ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 0 ⎦ ⎣33⎦ ⎣ −33⎦ • The following would give an error » c = row + column • Use the transpose to make sizes compatible » c = row’ + column » c = row + column’ • Can sum up or multiply elements of vector » s=sum(row); » p=prod(row);
  • 30. Element-Wise Functions • All the functions that work on scalars also work on vectors » t = [1 2 3]; » f = exp(t); is the same as » f = [exp(1) exp(2) exp(3)]; • If in doubt, check a function’s help file to see if it handles vectors elementwise • Operators (* / ^) have two modes of operation element-wise standard
  • 31. Operators: element-wise • To do element-wise operations, use the dot. BOTH dimensions must match (unless one is scalar)! » a=[1 2 3];b=[4;2;1]; » a.*b, a./b, a.^b all errors » a.*b’, a./b’, a.^(b’) all valid ⎡ 4⎤ ⎡1 1 1 ⎤ ⎡1 2 3⎤ ⎡ 1 2 3⎤ ⎢ 2 2 2 ⎥ .* ⎢1 2 3⎥ = ⎢ 2 4 6 ⎥ [1 2 3] .* ⎢ 2⎥ = ERROR ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢1 ⎥ ⎣ ⎦ ⎢ 3 3 3 ⎥ ⎢1 2 3⎥ ⎢ 3 6 9 ⎥ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎡1 ⎤ ⎡ 4⎤ ⎡ 4⎤ 3 × 3.* 3 × 3 = 3 × 3 ⎢ 2 ⎥ .* ⎢ 2 ⎥ = ⎢ 4 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 3⎥ ⎢1 ⎥ ⎢ 3⎥ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎡1 2 ⎤ ⎡12 22 ⎤ 3 ×1.* 3 ×1 = 3 × 1 ⎢3 4 ⎥ .^ 2 = ⎢ 2 ⎥ ⎣ ⎦ ⎣ 3 42 ⎦ Can be any dimension
  • 32. Operators: standard • Multiplication can be done in a standard way or element-wise • Standard multiplication (*) is either a dot-product or an outer- product Remember from linear algebra: inner dimensions must MATCH!! • Standard exponentiation (^) implicitly uses * Can only be done on square matrices or scalars • Left and right division (/ ) is same as multiplying by inverse Our recommendation: just multiply by inverse (more on this later) ⎡ 4⎤ ⎡1 2 ⎤ ⎡1 2 ⎤ ⎡1 2 ⎤ ⎡1 1 1⎤ ⎡1 2 3⎤ ⎡3 6 9 ⎤ [1 2 3]* ⎢ 2⎥ = 11 ⎢ ⎥ ⎢3 4 ⎥ ⎣ ⎦ ^2=⎢ ⎥ * ⎢3 4 ⎥ ⎣3 4 ⎦ ⎣ ⎦ ⎢2 2 2⎥ * ⎢1 2 3⎥ = ⎢6 12 18 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢1 ⎥ ⎣ ⎦ Must be square to do powers ⎢3 3 3⎥ ⎢1 2 3⎥ ⎢9 18 27⎥ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ 1× 3* 3 ×1 = 1× 1 3 × 3* 3 × 3 = 3 × 3
  • 33. Exercise: Vector Operations • Find the inner product between [1 2 3] and [3 5 4] » a=[1 2 3]*[3 5 4]’ • Multiply the same two vectors element-wise » b=[1 2 3].*[3 5 4] • Calculate the natural log of each element of the resulting vector » c=log(b)
  • 34. Automatic Initialization • Initialize a vector of ones, zeros, or random numbers » o=ones(1,10) row vector with 10 elements, all 1 » z=zeros(23,1) column vector with 23 elements, all 0 » r=rand(1,45) row vector with 45 elements (uniform [0,1]) » n=nan(1,69) row vector of NaNs (useful for representing uninitialized variables) The general function call is: var=zeros(M,N); Number of rows Number of columns
  • 35. Automatic Initialization • To initialize a linear vector of values use linspace » a=linspace(0,10,5) starts at 0, ends at 10 (inclusive), 5 values • Can also use colon operator (:) » b=0:2:10 starts at 0, increments by 2, and ends at or before 10 increment can be decimal or negative » c=1:5 if increment isn’t specified, default is 1 • To initialize logarithmically spaced values use logspace similar to linspace
  • 36. Exercise: Vector Functions • Make a vector that has 10,000 samples of f(x) = e^{-x}*cos(x), for x between 0 and 10. » x = linspace(0,10,10000); » f = exp(-x).*cos(x);
  • 37. Vector Indexing • MATLAB indexing starts with 1, not 0 We will not respond to any emails where this is the problem. • a(n) returns the nth element [13 5 9 10] a(1) a(2) a(3) a(4) • The index argument can be a vector. In this case, each element is looked up individually, and returned as a vector of the same size as the index vector. » x=[12 13 5 8]; » a=x(2:3); a=[13 5]; » b=x(1:end-1); b=[12 13 5];
  • 38. Matrix Indexing • Matrices can be indexed in two ways using subscripts (row and column) using linear indices (as if matrix is a vector) • Matrix indexing: subscripts or linear indices b(1,1) ⎡14 33⎤ b(1,2) b(1) ⎡14 33⎤ b(3) b(2,1) ⎢9 8⎥ b(2,2) b(2) ⎢9 8⎥ b(4) ⎣ ⎦ ⎣ ⎦ • Picking submatrices » A = rand(5) % shorthand for 5x5 matrix » A(1:3,1:2) % specify contiguous submatrix » A([1 5 3], [1 4]) % specify rows and columns
  • 39. Advanced Indexing 1 • The index argument can be a matrix. In this case, each element is looked up individually, and returned as a matrix of the same size as the index matrix. » a=[-1 10 3 -2]; ⎡ −1 10 −2 ⎤ b=⎢ ⎥ » b=a([1 2 4;3 4 2]); ⎣ 3 −2 10 ⎦ • To select rows or columns of a matrix, use the : ⎡12 5 ⎤ c=⎢ ⎣ −2 13⎥ ⎦ » d=c(1,:); d=[12 5]; » e=c(:,2); e=[5;13]; » c(2,:)=[3 6]; %replaces second row of c
  • 40. Advanced Indexing 2 • MATLAB contains functions to help you find desired values within a vector or matrix » vec = [1 5 3 9 7] • To get the minimum value and its index: » [minVal,minInd] = min(vec); • To get the maximum value and its index: » [maxVal,maxInd] = max(vec); • To find any the indices of specific values or ranges » ind = find(vec == 9); » ind = find(vec > 2 & vec < 6); find expressions can be very complex, more on this later • To convert between subscripts and indices, use ind2sub, and sub2ind. Look up help to see how to use them.
  • 41. Exercise: Vector Indexing • Evaluate a sine wave at 1,000 points between 0 and 2*pi. • What’s the value at Index 55 Indices 100 through 110 • Find the index of the minimum value, the maximum value, and values between -0.001 and 0.001 » x = linspace(0,2*pi,1000); » y=sin(x); » y(55) » y(100:110) » [minVal,minInd]=min(y) » [maxVal,maxInd]=max(y) » inds=find(y>-0.001 & y<0.001)
  • 42. BONUS Exercise: Matrices • Make a 3x100 matrix of zeros, and a vector x that has 100 values between 0 and 10 » mat=zeros(3,100); » x=linspace(0,10,100); • Replace the first row of the matrix with cos(x) » mat(1,:)=cos(x); • Replace the second row of the matrix with log((x+2)^2) » mat(2,:)=log((x+2).^2); • Replace the third row of the matrix with a random vector of the correct size » mat(3,:)=rand(1,100); • Use the sum function to compute row and column sums of mat (see help) » rs = sum(mat,2); » cs = sum(mat); % default dimension is 1
  • 43. Outline (1) Getting Started (2) Making Variables (3) Manipulating Variables (4) Basic Plotting
  • 44. Plotting Vectors • Example » x=linspace(0,4*pi,10); » y=sin(x); • Plot values against their index » plot(y); • Usually we want to plot y versus x » plot(x,y); MATLAB makes visualizing data fun and easy!
  • 45. What does plot do? • plot generates dots at each (x,y) pair and then connects the dots with a line • To make plot of a function look smoother, evaluate at more points » x=linspace(0,4*pi,1000); » plot(x,sin(x)); • x and y vectors must be same size or else you’ll get an error » plot([1 2], [1 2 3]) error!! 1 1 10 x values: 0.8 0.6 1000 x values: 0.8 0.6 0.4 0.4 0.2 0.2 0 0 -0.2 -0.2 -0.4 -0.4 -0.6 -0.6 -0.8 -0.8 -1 -1 0 2 4 6 8 10 12 14 0 2 4 6 8 10 12 14
  • 46. Plot Options • Can change the line color, marker style, and line style by adding a string argument » plot(x,y,’k.-’); color marker line-style • Can plot without connecting the dots by omitting line style argument » plot(x,y,’.’) • Look at help plot for a full list of colors, markers, and linestyles
  • 47. Other Useful plot Commands • Much more on this in Lecture 2, for now some simple commands • To plot two lines on the same graph » hold on; • To plot on a new figure » figure; » plot(x,y); • Play with the figure GUI to learn more add axis labels add a title add a grid zoom in/zoom out
  • 48. Exercise: Plotting • Plot f(x) = e^x*cos(x) on the interval x = [0 10]. Use a red solid line with a suitable number of points to get a good resolution. » x=0:.01:10; » plot(x,exp(x).*cos(x),’r’);
  • 49. End of Lecture 1 (1) Getting Started (2) Making Variables (3) Manipulating Variables (4) Basic Plotting Hope that wasn’t too much!!