Manipulating MATLAB Matrices Chapter 4

Slides:



Advertisements
Similar presentations
Lecture 4.
Advertisements

1 Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter 4-1 Systems of Equations and Inequalities Chapter 4.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
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.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 2 Systems of Linear Equations and Matrices Section 2.4 Multiplication of Matrices.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
10.4 Matrix Algebra 1.Matrix Notation 2.Sum/Difference of 2 matrices 3.Scalar multiple 4.Product of 2 matrices 5.Identity Matrix 6.Inverse of a matrix.
Unit 3: Matrices.
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.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Working with Arrays in MATLAB
Chapter 2 Creating Arrays Legend: MATLAB command or syntax : Blue MATLAB command OUTPUT : LIGHT BLUE.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Array Creation ENGR 1181 MATLAB 2. Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data.
LESSON 3 MATRICES Azalya Rahmatika Fathul Fithrah JURUSAN MATEMATIKA FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM UNIVERSITAS SYIAH KUALA DARUSSALAM,
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
10.4 Matrix Algebra 1.Matrix Notation 2.Sum/Difference of 2 matrices 3.Scalar multiple 4.Product of 2 matrices 5.Identity Matrix 6.Inverse of a matrix.
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 1320 Chapter 3: Systems of Linear Equations and Matrices 3.2 Using Matrices to Solve Systems of Equations.
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.
Unit 3: Matrices. Matrix: A rectangular arrangement of data into rows and columns, identified by capital letters. Matrix Dimensions: Number of rows, m,
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 =
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.
Matrices IB Mathematics SL. Matrices Describing Matrices Adding Matrices.
MTH108 Business Math I Lecture 20.
12-4: Matrix Methods for Square Systems
Sections 2.4 and 2.5 Matrix Operations
12-1 Organizing Data Using Matrices
ECE 1304 Introduction to Electrical and Computer Engineering
Linear Algebra review (optional)
Chapter 7 Matrix Mathematics
© 2016 Pearson Education, Ltd. All rights reserved.
Other Kinds of Arrays Chapter 11
Matrix Operations SpringSemester 2017.
Multiplying Matrices.
WarmUp 2-3 on your calculator or on paper..
Use of Mathematics using Technology (Maltlab)
Warmup Solve each system of equations. 4x – 2y + 5z = 36 2x + 5y – z = –8 –3x + y + 6z = 13 A. (4, –5, 2) B. (3, –2, 4) C. (3, –1, 9) D. no solution.
Multiplying Matrices.
Vectors and Matrices I.
Chapter 4 Systems of Linear Equations; Matrices
Unit 3: Matrices
2.2 Introduction to Matrices
Communication and Coding Theory Lab(CS491)
Arrays and Matrices in MATLAB
Array Creation ENGR 1181 MATLAB 02.
Multiplying Matrices.
Linear Algebra review (optional)
Chapter 4 Systems of Linear Equations; Matrices
Math review - scalars, vectors, and matrices
MATRICES MATRIX OPERATIONS.
Matrix Operations Ms. Olifer.
Matrix Operations SpringSemester 2017.
Multiplying Matrices.
Working with Arrays in MATLAB
Multiplying Matrices.
Multiplying Matrices.
Presentation transcript:

Manipulating MATLAB Matrices Chapter 4

Objectives After studying this chapter you should be able to: Manipulate matrices Extract data from matrices Solve problems with two variables Explore some of the special matrices built into MATLAB

Section 4.1 Manipulating Matrices We’ll start with a brief review To define a matrix, type in a list of numbers enclosed in square brackets

Remember that we can define a matrix using the following syntax B=[1.5, 3.1] or B=[1.5 3.1] C=[-1, 0, 0; 1, 1, 0; 0, 0, 2];

2-D Matrices can also be entered by listing each row on a separate line 1, 1, 0 1, -1, 0 0, 0, 2]

Use an ellipsis to continue a definition onto a new line 55, 82, 22, 109];

Scalar

Vector – the commas are optional

2-D matrix These semicolons are optional

You can define a matrix using other matrices as components

Or…

Indexing Into an Array allows you to change a value

Adding Elements

If you add an element outside the range of the original array, intermediate elements are added with a value of zero

4.1.2 Colon Operator Used to define new matrices Modify existing matrices Extract data from existing matrices

Evenly spaced vector The default spacing is 1

User specified spacing The spacing is specified as 0.5

The colon can be used to represent an entire row or column All the rows in column 1 All the rows in column 4 All the columns in row 1 The colon can be used to represent an entire row or column

You don’t need to extract an entire row or column Rows 2 to 3, all the columns

Or… Rows 2 to 3, in columns 4 to 5

A single colon transforms the matrix into a column MATLAB is column dominant

Indexing techniques To identify an element in a 2-D matrix use the row and column number For example element M(2,3)

Element M(2,3) is in row 2, column 3

1 4 7 10 13 2 5 8 11 14 3 6 9 12 15 Or use single value indexing M(8) is the same element as M(2,3) Element #s 1 4 7 10 13 2 5 8 11 14 3 6 9 12 15

The word “end” signifies the last element in the row or column Row 1, last element Last row, last element Last element in the single index designation scheme

Section 4.2 Problems with Two Variables All of our calculations thus far have only included one variable Most physical phenomena can vary with many different factors We need a strategy for determining the array of answers that results with a range of values for multiple variables

Two scalars give a scalar result

A scalar and a vector give a vector result

When you multiply two vectors together, they must have the same number of elements

Array multiplication gives a result the same size as the input arrays x and y must be the same size

Results of an element by element (array) multiplication x 1 2 3 4 5 y 1.0 1.5 2.0 6 2.5 10 3.0 ? 15

The meshgrid function maps two vectors onto a 2-D grid

Now the arrays are the same size, and can be multiplied

Example 4.2 Distance to the Horizon Radius of the earth Distance to the horizon Height of the mountain Radius of the earth, R Radius plus the height of the mountain, R+h Distance to the horizon, d

State the problem Find the distance to the horizon from the top of a mountain on the moon and on the earth

Describe the Input and Output Radius of the Moon 1737 km Radius of the Earth 6378 km Mountain elevation 0 to 8000km Output Distance to the horizon in km

Hand Example Pythagorean theorum Solve for d Using the radius of the earth, and an 8000 meter mountain. (Remember 8000m = 8 km)

MATLAB Solution

Executing the M-file gives

Test the Solution Compare the results to the hand solution

Section 4.3 Special Matrices zeros Creates a matrix of all zeros ones Creates a matrix of all ones diag Extracts a diagonal or creates an identity matrix magic Creates a “magic” matrix

With a single input a square matrix is created with the zeros or ones function

Two input arguments specify the number of rows and columns

The diag function When the input argument to the diag function is a square matrix, the diagonal is returned

The diag function When the input is a vector, it is used as the diagonal of an identity matrix

Magic Matrices

This woodcut called Melancholia was created by Albrect Durer, in 1514 This woodcut called Melancholia was created by Albrect Durer, in 1514. It contains a magic matrix above the angel’s head

Albrect Durer included the date in this magic matrix.

The Durer matrix is different from MATLAB’s 4x4 magic matrix Durer switched these two columns to make the date work out

Summary Matrices can be created by combining other matrices Portions of existing matrices can be extracted to form smaller matrices

Summary – The colon operator can be used to create evenly spaced matrices can be used to extract portions of existing matrices can be used to transform a 2-D matrix into a single column

Summary - Meshgrid Meshgrid is an extremely useful function that can be used to map vectors into two dimensional matrices This makes it possible to perform array calculations with vectors of unequal size

Summary – Special Matrices zeros – creates a matrix composed of all zeros ones – creates a matrix composed of all ones diag – extracts the diagonal from a square matrix or can be used to create a square matrix identity matrix magic – creates a “magic matrix”