Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.

Slides:



Advertisements
Similar presentations
CMPS 1371 Introduction to Computing for Engineers FUNCTIONS.
Advertisements

Maths for Computer Graphics
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
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 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
Builtin and user defined functions
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Matlab for Engineers Built-in Matlab Functions Chapter 3.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
Recap Script M-file Editor/Debugger Window Cell Mode Chapter 3 “Built in MATLAB Function” Using Built-in Functions Using the HELP Feature Window HELP.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Lec-10 Manipulations of Matlab Matrices. Built-in functions The chapter will be covered quickly There are quite a few built-in functions in MATLAB – If.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
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.
1 An Introduction to R © 2009 Dan Nettleton. 2 Preliminaries Throughout these slides, red text indicates text that is typed at the R prompt or text that.
Lecture 24: Rough and Ready Analysis. MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
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.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
ENG College of Engineering Engineering Education Innovation Center 1 Arrays in MATLAB Topics Covered: 1.Creating arrays of numbers vectors matrices.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
Introduction To MATLAB
Arithmetic Operations
Introduction to Matlab
ECE 1304 Introduction to Electrical and Computer Engineering
Manipulating MATLAB Matrices Chapter 4
Numeric, Cell and Structural Arrays One of the strenghts of MATLAB is the capabilty to handle collection of numbers called ARRAYS. MATLAB refers to scalars,
ECE 1304 Introduction to Electrical and Computer Engineering
Built-in MATLAB Functions Chapter 3
Computer Simulation Lab
Multiplying Matrices.
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
MATH 493 Introduction to MATLAB
Introduction to MATLAB Lecture 02
Multiplying Matrices.
2.2 Introduction to Matrices
Fourth Year – Software Engineering
Communication and Coding Theory Lab(CS491)
Stat 251 (2009, Summer) Lab 1 TA: Yu, Chi Wai.
Introduction to Matlab
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
Multiplying Matrices.
-seminar 1 for digital signal processing
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Matlab Basics Tutorial
Matrices in MATLAB Dr. Risanuri Hidayat.
EECS Introduction to Computing for the Physical Sciences
Multiplying Matrices.
Multiplying Matrices.
Computer Simulation Lab
Multiplying Matrices.
CHAPTER 3 Built-in MATLAB Functions
Presentation transcript:

Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s wife

What’s the output? >>A = [1 2 3; 3 5 6] >>B = [2 4 6; ] >>C = B./A This statement stores the matrix: 1. C= 2. C= 3. C= 4. Can’t divide these matrices

What’s the output? >>A = [1 2 3; 3 5 6] >>B = [2 4 6; ] >>C = B*A This statement stores the matrix: 1. C= 2. C= 3. C= 4.Can’t multiply these matrices: not the correct dimension – A is 2x3 B is 2x3

What’s the output? >>A = [1 2 3; 3 5 6] >>B = [1 1 1; 1 1 1] >>C = B*A’ This statement stores the matrix: 1. C= 2. C= 3. C= 4.Can’t multiply these matrices: not the correct dimension – A is 2x3 B is 2x3

What’s the output? >>A = [0:0.1:0.5] This statement stores the matrix: 1. A= 2. A= 3. A= 4.A =

NEXT TOPIC: MATLAB FUNCTIONS

MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log

Function Input can be either scalars or matrices

Some functions return multiple results size function determines the number of rows and columns

You can assign names to the output

There are functions for almost anything you want to do Use the help feature to find out what they are and how to use them From the command window From the help selection on the menu bar

Elementary Math Functions abs(x)absolute value sign(x)plus or minus exp(x)e x log(x) natural log log10(x)log base 10

Rounding Functions round(x) fix(x) floor(x) ceil(x)

Trigonometric Functions sin(x)sine cos(x)cosine tan(x)tangent asin(x)inverse sine sinh(x)hyperbolic sine asinh(x)inverse hyperbolic sine sind(x)sine with degree input asind(x)inverse sin with degree output

Data Analysis max(x) min(x) mean(x) median(x) sum(x) prod(x) sort(x)

When x is a matrix, the max is found for each column

max valueelement number where the max value occurs Returns both the smallest value in a vector x and its location in vector x.

Vector of maximums Vector of row numbers Returns a row vector containing the minimum element from each column of a matrix x, and returns a row vector of the location of the minimum in each column of matrix x.

Determining Matrix Size size(x)number of rows and columns length(x)biggest dimension

Variance and Standard Deviation std(x) var(x)

Random Numbers rand(n) Returns an n by n matrix of random numbers between 0 and 1 rand(n,m) Returns an n by m matrix of random numbers These random numbers are evenly distributed

Gaussian Random Numbers randn(n) Returns an n by n matrix of Gaussian (i.e. normal) random numbers with a mean of zero and a variance of 1. randn(n,m) Returns an n by m matrix of Gaussian (i.e. normal) random numbers with a mean of 0 and variance of 1

Manipulating Matrices Defining matrices A matrix can be defined by typing in a list of numbers enclosed in square brackets. The numbers can be separated by spaces or commas. New rows are indicated with a semicolon. A = [ 3.5 ]; B = [1.5, 3.1]; or B =[ ]; C = [-1, 0, 0; 1, 1, 0; 0, 0, 2];

Manipulating Matrices Defining matrices Define a matrix by using another matrix that has already been defined. Reference an element in a matrix Both row and column indices start from 1. B = [1.5, 3.1]; S = [3.0, B] S = [3.0, 1.5, 3.1]; T = [1 2 3; S] S = T = S(2) T(2, 2) T(4) The element value on row 2 and column 2 of matrix T Count down column 1, then down column 2, and finally down column 2 to the correct element of matrix T.

Manipulating Matrices Change values in a matrix S(2) = -1.0; changes the 2nd value in the matrix S from 1.5 to -1.0 Extend a matrix by defining new elements. S(4) = 5.5; Extend the matrix S to four elements instead of three. S(8) = 9.5; Matrix S will have eight values, and the values of S(5), S(6), S(7) will be set to 0. T(3, 3) = 10; T(4, 5) = 20;

Manipulating Matrices Using the colon operator Define an evenly spaced matrix H = 1:8 --- The default spacing is 1 time = 0.0:0.5: The middle value becomes the spacing. Extract data from matrices x = M( :, 1) --- extract column 1 from matrix M y = M( :, 4) --- extract column 4 from matrix M z = M(2, : ) --- extract row 2 from matrix M a = M(2:3, : ) --- extract rows 2 and 3 from matrix M b = M( :, 2:4) --- extract column 2 to column 4 from matrix M c = M(2:3, 3:5) --- extract not whole rows or whole columns from matrix M Converts a two dimensional matrix to a single column M( : ) M =