Matlab for Engineers Manipulating Matlab Matrices Chapter 4.

Slides:



Advertisements
Similar presentations
2.3 Modeling Real World Data with Matrices
Advertisements

Lecture 4.
Further Pure 1 Matrices Introduction. Definitions A matrix is just a rectangle of numbers. It’s a bit like a two-way table. You meet this concept in D1.
1 Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter 4-1 Systems of Equations and Inequalities Chapter 4.
Maths for Computer Graphics
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
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.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
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.
Matrix Solution of Linear Systems The Gauss-Jordan Method Special Systems.
Chapter 10 Review: Matrix Algebra
MATLAB Basics With a brief review of linear algebra by Lanyi Xu modified by D.G.E. Robertson.
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.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Row 1 Row 2 Row 3 Row m Column 1Column 2Column 3 Column 4.
CMPS 1371 Introduction to Computing for Engineers MATRICES.
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.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Lesson 11-1 Matrix Basics and Augmented Matrices Objective: To learn to solve systems of linear equation using matrices.
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
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
Chapter 2 Creating Arrays Legend: MATLAB command or syntax : Blue MATLAB command OUTPUT : LIGHT BLUE.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Section 4Chapter 4. 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Objectives Solving Systems of Linear Equations by Matrix Methods Define.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
(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.
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.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
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 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.
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.
Sections 2.4 and 2.5 Matrix Operations
12-1 Organizing Data Using Matrices
ECE 1304 Introduction to Electrical and Computer Engineering
Manipulating MATLAB Matrices Chapter 4
Chapter 7 Matrix Mathematics
Matrix Operations SpringSemester 2017.
Multiplying Matrices.
Multiplying Matrices.
Vectors and Matrices I.
Communication and Coding Theory Lab(CS491)
Array Creation ENGR 1181 MATLAB 02.
Chapter 4 Systems of Linear Equations; Matrices
Matrix Operations SpringSemester 2017.
Working with Arrays in MATLAB
Presentation transcript:

Matlab for Engineers Manipulating Matlab Matrices Chapter 4

Matlab for Engineers In this chapter we’ll Learn how to manipulate matrices Solve problems with two variables Explore some of the special matrices built into Matlab

Matlab for Engineers Section 4.1 Manipulating Matices We’ll start with a brief review Define a matrix type in a list of numbers enclosed in square brackets

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

Matlab for Engineers 2-D Matrices can also be entered by listing each row on a separate line C = [-1, 0, 0 1, 1, 0 1, -1, 0 0, 0, 2]

Matlab for Engineers F = [1, 52, 64, 197, 42, -42, … 55, 82, 22, 109]; Use an ellipsis to continue a definition onto a new line

Matlab for Engineers Scalar

Matlab for Engineers Vector – the commas are optional

Matlab for Engineers 2-D matrix These semicolons are optional

Matlab for Engineers You can define a matrix using other matrices as components

Matlab for Engineers Or…

Matlab for Engineers Indexing Into an Array allows you to change a value

Matlab for Engineers Adding Elements

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

Matlab for Engineers Colon Operator Used to define new matrices Modify existing matrices Extract data from existing matrices

Matlab for Engineers Evenly spaced vector The default spacing is 1

Matlab for Engineers User specified spacing The spacing is specified as 0.5

Matlab for Engineers 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

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

Matlab for Engineers Or… Rows 2 to 3, in columns 4 to 5

Matlab for Engineers A single colon transforms the matrix into a column Matlab is column dominant

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

Matlab for Engineers Element M(2,3) is in row 2, column 3

Matlab for Engineers Or use single value indexing M(8) is the same element as M(2,3) Element #s

Matlab for Engineers 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

Matlab for Engineers

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

Matlab for Engineers Two scalars give a scalar result

Matlab for Engineers A scalar and a vector give a vector result

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

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

Matlab for Engineers Results of an element by element (array) multiplication x y ?15

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

Matlab for Engineers Now the arrays are the same size, and can be multiplied

Matlab for Engineers Try it out!

Matlab for Engineers 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

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

Matlab for Engineers Describe the Input and Output Input Radius of the Moon1737 km Radius of the Earth6378 km Mountain elevation0 to 8000km Output Distance to the horizon in km

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

Matlab for Engineers Matlab Solution

Matlab for Engineers Executing the M-file gives

Matlab for Engineers Test the Solution Compare the results to the hand solution

Matlab for Engineers 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

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

Matlab for Engineers Two input arguments specify the number of rows and columns

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

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

Matlab for Engineers Magic Matrices

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

Matlab for Engineers Albrect Durer included the date in this magic matrix.

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

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

Matlab for Engineers Summary – The colon operator 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

Matlab for Engineers 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

Matlab for Engineers 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”