Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

Maths for Computer Graphics
Wednesday, July 15, 2015 EQ: What are the similarities and differences between matrices and real numbers ? Warm Up Evaluate each expression for a = -5,
Part 3 Chapter 8 Linear Algebraic Equations and Matrices PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The.
Finding the Inverse of a Matrix
Matrix Definition A Matrix is an ordered set of numbers, variables or parameters. An example of a matrix can be represented by: The matrix is an ordered.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
1 Chapter 3 Matrix Algebra with MATLAB Basic matrix definitions and operations were covered in Chapter 2. We will now consider how these operations are.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
4.1 Using Matrices to Represent Data
Chapter 10 Review: Matrix Algebra
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.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
4.1 Matrix Operations What you should learn: Goal1 Goal2 Add and subtract matrices, multiply a matrix by a scalar, and solve the matrix equations. Use.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
Matrices Addition & Subtraction Scalar Multiplication & Multiplication Determinants Inverses Solving Systems – 2x2 & 3x3 Cramer’s Rule.
Lecture 28: Mathematical Insight and Engineering.
Unit 6 : Matrices.
Matrix Multiplication The inner dimensions must be the same (or the number of columns in the first matrix is equal to the number of rows in the second.
Matrix Arithmetic. A matrix M is an array of cell entries (m row,column ) and it must have rectangular dimensions (Rows x Columns). Example: 3x x.
13.1 Matrices and Their Sums
Lesson 11-1 Matrix Basics and Augmented Matrices Objective: To learn to solve systems of linear equation using matrices.
Prepared by Deluar Jahan Moloy Lecturer Northern University Bangladesh
ES 240: Scientific and Engineering Computation. Chapter 8 Chapter 8: Linear Algebraic Equations and Matrices Uchechukwu Ofoegbu Temple University.
Meeting 18 Matrix Operations. Matrix If A is an m x n matrix - that is, a matrix with m rows and n columns – then the scalar entry in the i th row and.
4.1 Using Matrices Warm-up (IN) Learning Objective: to represent mathematical and real-world data in a matrix and to find sums, differences and scalar.
Matrices: Simplifying Algebraic Expressions Combining Like Terms & Distributive Property.
Sec 4.1 Matrices.
MT411 Robotic Engineering Asian Institution of Technology (AIT) Chapter 1 Introduction to Matrix Narong Aphiratsakun, D.Eng.
Algebra Matrix Operations. Definition Matrix-A rectangular arrangement of numbers in rows and columns Dimensions- number of rows then columns Entries-
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.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Linear System of Simultaneous Equations Warm UP First precinct: 6 arrests last week equally divided between felonies and misdemeanors. Second precinct:
ENG College of Engineering Engineering Education Innovation Center 1 Array Operations in MATLAB 1.Types of Matrix arithmetic 2.Dot operators Mathematical.
Unit 3: Matrices. Matrix: A rectangular arrangement of data into rows and columns, identified by capital letters. Matrix Dimensions: Number of rows, m,
Precalculus Section 14.1 Add and subtract matrices Often a set of data is arranged in a table form A matrix is a rectangular.
Chapter 5: Matrices and Determinants Section 5.1: Matrix Addition.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
A rectangular array of numeric or algebraic quantities subject to mathematical operations. The regular formation of elements into columns and rows.
10.4 Matrix Algebra. 1. Matrix Notation A matrix is an array of numbers. Definition Definition: The Dimension of a matrix is m x n “m by n” where m =
MTH108 Business Math I Lecture 20.
Sections 2.4 and 2.5 Matrix Operations
Linear Algebraic Equations and Matrices
12-1 Organizing Data Using Matrices
Chapter 7 Matrix Mathematics
Linear Algebraic Equations and Matrices
Introduction To Matrices
Matrix Operations Monday, August 06, 2018.
Matrix Operations.
Matrix Operations SpringSemester 2017.
EGR 106 – Week 4 – Math on Arrays
Multiplying Matrices.
Warm-up a. Solve for k: 13 −5
MATRICES MATRIX OPERATIONS.
2.2 Introduction to Matrices
Objectives Multiply two matrices.
Multiplying Matrices.
3.5 Perform Basic Matrix Operations
3.6 Multiply Matrices.
Chapter 4 Matrices & Determinants
1.8 Matrices.
Matrix Operations Ms. Olifer.
Matrix Operations SpringSemester 2017.
1.8 Matrices.
Multiplying Matrices.
Multiplying Matrices.
Multiplying Matrices.
Presentation transcript:

Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays

Working with Arrays Chapter Outline Creating Vector and Matrix Accessing and Addressing Matrix Mathematical Operations with Matrix Functions for Analyzing Matrix Chapter Case Study

Working with Arrays Creating Vectors a n subdivision points b dx >> x = a:dx:b; >> x = linspace(a,b,n); >> x = x'; x row vectors convert to column vector

Working with Arrays Creating Vectors - Examples 1)Create a COLUMN VECTOR with the elements : 55, 14, log(51), 0, sin(pi/3) 2) Create a ROW VECTOR which the first element is 1, the last element is 33, with a increment of 2 between elements

Working with Arrays Creating Matrices >> A = [1,2,3; 4,5,6; 7,8,9]; >> A = [1 2 3; 4 5 6; 7 8 9]; >> A = [ ] >> A = A' or data entry mode transpose

Working with Arrays Array Operations A = B = C = A + B C = A = B = C = A.*B C = Array addition Array multiplication A = C = A.^2 C = Array power

Working with Arrays Array Multiplication Matrices must have the same dimensions Dimensions of resulting matrix = dimensions of multiplied matrices Resulting elements = product of corresponding elements from the original matrices >> a = [ ; ]; >> b = [1:4; 1:4]; >> c = a.*b c = >> a = [ ; ]; >> b = [1:4; 1:4]; >> c = a.*b c = c(2,4) = a(2,4)*b(2,4)

Working with Arrays Matrix Operations A = B = 2*A B = A = B = 2 + A B = Scalar Multiplication Scalar Expansion A = B = C = A * B C = Matrix Multiplication

Working with Arrays >> e=[1 2;3 4] = = = 8 9 >> e=[1 2;3 4] = = = 8 9 Matrix Calculation-Scalar Expansion >> e=[1 2;3 4] + 5 e = >> e=[1 2;3 4] + 5 e = Scalar expansion

Working with Arrays Matrix Multiplication Inner dimensions must be equal. Dimension of resulting matrix = outermost dimensions of multiplied matrices. Resulting elements = dot product of the rows of the 1st matrix with the columns of the 2nd matrix. >> a = [1 2 3;4 5 6]; >> b = [3,1;2,4;-1,2]; >> c = a*b c = >> a = [1 2 3;4 5 6]; >> b = [3,1;2,4;-1,2]; >> c = a*b c = [2x3] [3x2] [2x3]*[3x2] [2x2] a(2nd row). b(2nd column)

Working with Arrays Array Addressing m(2:4,3) m(3,1)

Working with Arrays More Example on indexing >> a=[3 11 6; ; ] a = >> a(3,1)= 20 a = >> a(2,3)-a(1,2) ans = >> a=[3 11 6; ; ] a = >> a(3,1)= 20 a = >> a(2,3)-a(1,2) ans = Create a 3 x 3 matrix Use square brackets [ ] Matrices must be rectangular. (Undefined elements set to zero) Assign a new value to the (3,1) element Use elements in a mathematical expression

Working with Arrays More Example on Colon indexing >> a=[3 11 6; ; ] a = >> b = a(:,3) b = >> c = a(2,:) c = >> d = a(2:3,1:2) d = [4 7 ] [13 9 ] >> a=[3 11 6; ; ] a = >> b = a(:,3) b = >> c = a(2,:) c = >> d = a(2:3,1:2) d = [4 7 ] [13 9 ] Create a 3 x 3 matrix Define a column vector b from elements in all rows of column 3 in matrix a Define a row vector c from elements in all columns of row 2 in matrix a Create a matrix d from elements in rows 2&3 and columns 1&2 in matrix a

Working with Arrays Solve this set of simultaneous equations Array Division using “Left Division” >> A = [-1 1 2; ;-1 3 4]; >> b = [2;6;4]; >> x = inv(A)*b x = >> x = A\b x = >> A = [-1 1 2; ;-1 3 4]; >> b = [2;6;4]; >> x = inv(A)*b x = >> x = A\b x = x 1 + x 2 + 2x 3 = 2 3x 1 - x 2 + x 3 = 6 -x 1 + 3x 2 + 4x 3 = 4

Working with Arrays FunctionDescriptionExample C=max(A)If A is vector, C is the largest element in A A = [5 9 2] C = max(A) sum(A)If A is vector, returns the sum of elements of A A = [5 9 2] sum(A) sort(A)If A is vector, arranges elements of vector in ascending order A = [5 9 2] sort(A) det(A)Returns the determinant of a square matrix A A = [2 4; 3 5]; det (A) inv(A)Returns the inverse of a square matrix A A = [2 4; 3 5]; inv(A) Functions for Analyzing Matrix

Working with Arrays Sample Problem 2 : Friction Experiment The coefficient of friction, μ, can be determined in an experiment by measuring the force F required to move a mass m. When F is measured and m is known, the coefficient of friction can be calculated by: µ = F / (mg) where g = 9.81 m/s 2 Results from measuring F in six tests are given in the table below. Determine the coefficient of friction in each test, and the average from all tests. Test # Mass m (kg) Force F (N)

Working with Arrays Summary Creating Vector and Matrix Accessing and Addressing Matrix Mathematical Operations with Matrix Functions for Analyzing Matrix