INTRODUCTION TO MATLAB DAVID COOPER SUMMER 2014. Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work 12 1314.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

1 Chapter 4 Curve Plotting with MATLAB MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed.
Yuval Hart, Weizmann 2010 © 1 Introduction to Matlab & Data Analysis Tutorial 2 and 3: Variables and Matrix Manipulation.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
Eilon Sharon, Weizmann 2008 © 1 Introduction to Matlab & Data Analysis Tutorial 2: Variables and Matrix Manipulation.
Review of Matrix Algebra
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
EGR 106 – Week 3 – More on Arrays Brief review of last week Additional ideas: – Special arrays – Changing an array – Some array operators – Character arrays.
Matrix Mathematics in MATLAB and Excel
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Matrices The Basics Vocabulary and basic concepts.
Lecture 7: Matrix-Vector Product; Matrix of a Linear Transformation; Matrix-Matrix Product Sections 2.1, 2.2.1,
Intro to Matrices Don’t be scared….
MATRICES MATRIX OPERATIONS. About Matrices  A matrix is a rectangular arrangement of numbers in rows and columns. Rows run horizontally and columns run.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MATLAB Fundamentals.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
Algebra 2: Lesson 5 Using Matrices to Organize Data and Solve Problems.
Matlab tutorial course Lesson 2: Arrays and data types
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Matlab Chapter 2: Array and Matrix Operations. What is a vector? In Matlab, it is a single row (horizontal) or column (vertical) of numbers or characters.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Overview Definitions Basic matrix operations (+, -, x) Determinants and inverses.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Chapter 2 Creating Arrays Legend: MATLAB command or syntax : Blue MATLAB command OUTPUT : LIGHT BLUE.
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
LESSON 3 MATRICES Azalya Rahmatika Fathul Fithrah JURUSAN MATEMATIKA FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM UNIVERSITAS SYIAH KUALA DARUSSALAM,
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Matrices and Matrix Operations. Matrices An m×n matrix A is a rectangular array of mn real numbers arranged in m horizontal rows and n vertical columns.
MATRIX A set of numbers arranged in rows and columns enclosed in round or square brackets is called a matrix. The order of a matrix gives the number of.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
CS 450: COMPUTER GRAPHICS TRANSFORMATIONS SPRING 2015 DR. MICHAEL J. REALE.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
An Introduction to Programming in Matlab Emily Blumenthal
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
ECE 1304 Introduction to Electrical and Computer Engineering
Chapter 7 Matrix Mathematics
Chapter 3 Arrays and Vectors
MATLAB DENC 2533 ECADD LAB 9.
EEE 244 Numerical Methods In Electrical Engineering
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
MATRICES MATRIX OPERATIONS.
MATRICES MATRIX OPERATIONS.
2.2 Introduction to Matrices
INTRODUCTION TO MATLAB
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
Matlab Training Session 2: Matrix Operations and Relational Operators
MATRICES MATRIX OPERATIONS.
MATRICES MATRIX OPERATIONS.
Matrix Operations Ms. Olifer.
Presentation transcript:

INTRODUCTION TO MATLAB DAVID COOPER SUMMER 2014

Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work Plots 1516 Figures 1718 Work Simulation 2223 Curve Fitting 2425 Work Fourier Transforms 56 2D Fourier 78 Work Correlation 1213 Class Wrap-up

Basic Terminology bit –the basic unit of computation –(0, 1) byte –set of 8 bits –smallest unit of memory base 2 system 1 byte can represent the numbers from 0 to 255 Writing out a byte each place corresponds to the following – For example 42 = = =

Basic Terminology boolean –1 bit –(true, false) double –up to 17 sig figs –traditional number –64 bits string –a series of char of any length –any text you use in MATLAB is considered to be a string int –integer (1, 4, -5, ect) –a whole number –32 bits (-2 31 : 2 31 ) or (0 : 2 32 ) char –character –any letter, numbers 0- 9, and some key symbols –smallest form is 1 byte

MATLAB MATLAB stands for Matrix Laboratory and is a program designed for mathematical computation and manipulation Whenever you see ‘>>’ that will denote the use of a MATLAB command line. the ‘ENTER’ key will cause MATLAB to evaluate whatever text is on the line. ‘SHIFT + ENTER’ causes a new line to form without evaluating the text

MATLAB Screen

Matrix Terminology Scalar: a singular constant real number Vector: a 1-Dimensional array of any singular data type Matrix: a multi-Dimensional array of a singular data type Element: Any one member of a vector or matrix Array: General term for a matrix or vector Variable: Symbolic name unique identifier that contains some type of data to be used

Basic Commands =: used to define a variable –>> x = 3 ;: used to suppress the output of any command clear: removes all variables from the workspace clc: cleans the command window close: closes any extra windows such as figure windows clear and close can also have a modifier to perform on specific instances EX: clear x will only remove the variable x from the workspace

Vectors For most of the operations on vectors and matrices, the data type is unimportant and will be represented by a shape Row vectors are input using square brackets [ ] with a space or comma between each element >>[ ] ans = Column vectors are input using square brackets [ ] with a semicolon between each element where we ant a new row >>[1;2;3;4] ans =

Vectors To create a vector that has a regular interval the colon operator can be used >> 1:4 ans = The default interval is 1 but can be specified >> 1:0.5:4 ans = There is also the function linspace(), which allows for more control >> linspace(a,b) Generates a vector of 100 linearly spaced points that starts at a and ends at b >> linspace(a,b,n) Generates a vector of n linearly spaced points that starts at a and ends at b The function logspace() operates simmilarly but on the logrithmic scale

Matrices The most basic matrix would be a 2D array containing both rows and columns >>[ ; ] ans = Matrices are always defined ROWxCOLUMN The function size() will return the dimensions of the input matrix >> size([ ; ]) ans = 2 4 size() can also have a dimension specified, 1 for row, 2 for column >> size([ ; ],1) ans = 2 4 rows columns

Indexing Often times you will want to select a specific element from a matrix A = The most common method is to call A(row, column) using the subscripted index >> A(1,3) ans = You can also use the linear index >> A(7) ans = The two can be exchanged with the sub2ind() and ind2sub() functions >> index = sub2ind(size(A),row,col) >> [row col] = ind2sub(size(A),index) ,1 2,1 3,1 1,2 2,2 3,2 1,3 2,3 3,3 Note: the final index can be substituted for A(end)

Altering any element in a matrix works like assigning a variable A = You can also remove an element by assigning the desired index to be a blank vector [ ]. Note, unless you remove the entire row or column, you must use the linear index after which the resulting matrix becomes a row vector. >> A(3) = [] ans = To remove the entire row or column you must select it in the removal assignment, which can be done with a colon : >> A(2,:) ans = Changing Values >>A(1,3) = ans =

Matrix Addition To add (or subtract) a single scalar to an entire matrix use the following syntax >> A + 2 = [( +2), ( +2), ( +2)] To add two matrices together they must be the exact same dimensions or else an error will return. If they are, then the self same indices are added together and the resulting matrix is the same size as the two input. >> C = A + B C = [( + ), ( + ), ( + )] Two arrays can also be concatenated if they share a dimension >> C = [A B]>> C = [A ; B] C = A = [ ] B = [ ]

Matrix Multiplication Multiplying (or dividing) a scalar to an array works just like addition of a scalar >> 3*A = [(3* ), (3* ), (3* )] Multiplying two matrices is not as simple as just multiplying the elements together. The two matrices must have the column size of one match the row size of the other. >> A x B >> A x B’ It is also NOT commutative unlike multiplication for scalars. Order matters and the resulting matrix has the same number of rows as the first and the same number of columns as the second >> size(A*B’) >> size(B’*A) ans = B’ = A = [ ] B = [ ]

In matrix multiplication the elements of the rows of the first matrix are multiplied elementwise by the elements of the columns of the second matrix and then added together >> A*B’ = 1x3 * 3x1 = 1x1 >> B’*A = 3x1 * 1x3 = 3x3 * = ( * ) * = (( * )+( * )+( * ) = Matrix Multiplication B’ = A = [ ] 59

Matrix Multiplication Often we do not want to actually multiply two matrices but instead only multiply the corresponding elements. Note this can only be done between two matrices of the same size and results in a matrix of the same size as the multipliers Elementwise multiplication and division are done by adding a period directly before the operator >> C = A.* B C = [( * ), ( * ), ( * )] This can also be used for powers and root functions >> A.^2 >> B./(1/2) [ 2, 2, 2 ][,, ] A = [ ] B = [ ]

Useful Matrices The Identity matrix eye() is a matrix that has 1s along the diagonal and 0s everywhere else. It has the property that multiplying it in front of another matrix will return the second matrix >> Ident = eye(3)>> Ident*A Ident =ans = A The zeros() function creates a matrix comprised of nothing but 0s while the ones() function makes one that is nothing but 1s >> zeros(2,4)>> ones(4) ans = All of these functions can be called either with a single number (n), which will result in a square matrix of size nxn, or by specifying the dimensions with two numbers (n,m) creating a nxm matrix

Matrix Manipulation Transposing matrices causes the rows and columns to be exchanged To transpose a matrix the transpose() function can be used. Alternatively adding an apostrophe (‘) after an array will also transpose it >> A = [1 2 3;4 5 6;7 8 9] ans = You may also want to just flip a matrix over the horizontal or vertical axis >> flipud(A) ans = >>transpose(A) ans = >>fliplr(A) ans =

Matrix Manipulation Reshaping a vector into a matrix is also useful for some operations Reshaping is done via the reshape(A,n,m) command >> reshape(A,2,2) ans = Note that the new matrix size must have the same total number of elements as the old one To sort the elements of your matrix use the sort(A,dim) command >> S = [ ; ; ]; >> sort(S) ans = If no specified dimension is selected it sorts based on columns and will affect all columns To sort all of the elements but preserve the rows use sortrows() A = [ ] A =