Array Operations ENGR 1181 MATLAB 4.

Slides:



Advertisements
Similar presentations
Array Operations ENGR 1181 MATLAB 4. Aerospace Engineers use turbulence data to calculate how close other planes can fly near the wake of a larger plane.
Advertisements

Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Functions in MatLab Create a new folder on your Z:drive called MatLab_Class24 Start MatLab and change your current directory to MatLab_Class24 Topics:
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Maths for Computer Graphics
Introduction to Matlab. I use Matlab for: Data analysis Data plotting Image Analysis Also – Simulations (solving odes/pdes/finite element methods) – Minimisations,
Lecture 4 Sept 8 Complete Chapter 3 exercises Chapter 4.
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
EXPONENTS ORDER OF OPERATIONS MULTIPLYING / DIVIDING POWER OF A POWER POWER OF A PRODUCT POWER OF A QUOTIENT NEGATIVE EXPONENTS.
Modified Gary Larson Far Side cartoon
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 21P. 1Winter Quarter MATLAB: Structures.
Array Math.
Lecture 14: M/O/F/ for Engineering Applications - Part 2 BJ Furman 28NOV2011.
For Loops 2 ENGR 1181 MATLAB 9. For Loops and Looped Programming in Real Life As first introduced last lecture, looping within programs has long been.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
Functions 1 ENGR 1181 MATLAB 14.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
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.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Learner’s Guide to MATLAB® Chapter 2 : Working with Arrays.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
Ch 1.3 – Order of Operations
For Loops 1 ENGR 1181 MATLAB 8. For Loops and Looped Programming in Real Life Looping within programs has long been a useful tool for completing mundane.
CMPS 1371 Introduction to Computing for Engineers MATRICES.
Lecture 28: Mathematical Insight and Engineering.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Some Basic Math Concepts for Statistics
Lesson 11-1 Matrix Basics and Augmented Matrices Objective: To learn to solve systems of linear equation using matrices.
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.
Chapter 8 – Exponents and Exponential Functions 8.1/8.3 – Multiplication and Division Properties of Exponents.
1-2 Order of Operations and Evaluating Expressions.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
2D Plots 2 ENGR 1181 MATLAB 13. Plotting in the Real World 2D plots generated by MATLAB can be used in a variety of fields, including the one shown here,
While Loops ENGR 1181 MATLAB 10.
Introduction to Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
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.
One step equations Add Subtract Multiply Divide  When we solve an equation, our goal is to isolate our variable by using our inverse operations.  What.
Programming with Matlab Day 2: More about Loops, Vectors and Matrices.
User-Defined Functions in MATLAB. What is a function? From the conceptual standpoint, a “function” is a blackbox that transforms “input arguments” to.
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 MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Excel Graphing ENGR 1181 Class 5. Why use Excel?  Excel is a powerful spreadsheet program that can be used for: Creating graphical displays of data Performing.
Algebra 1 Warm Up.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Array Accessing and Strings ENGR 1187 MATLAB 3. Today's Topics  Array Addressing (indexing)  Vector Addressing (indexing)  Matrix Addressing (indexing)
Warm-up Answers:. Homework Answers: P3 (55-58 all, all, odds, all) /1690.
Section – Operations with Matrices No Calculator By the end of this lesson you should be able to: Write a matrix and identify its order Determine.
Project Teams Project on Diffusion will be a TEAM project. 34 Students in class so 6 teams of 5 and one Team of 4. Determine members of team and a team.
3.5 Perform Basic Matrix Operations Add Matrices Subtract Matrices Solve Matric equations for x and y.
ENG College of Engineering Engineering Education Innovation Center 1 Array Operations in MATLAB 1.Types of Matrix arithmetic 2.Dot operators Mathematical.
Do Now 9/20/12 Take out HW from last night. Take out HW from last night. Text p. 28, #8-24 evens, #17, 35, & 36 Text p. 28, #8-24 evens, #17, 35, & 36.
Logical Expressions ENGR 1181 MATLAB 6. Logical Expressions in Real Life Sorting objects in manufacturing processes can be accomplished automatically.
To add, subtract, multiply, and divide, absolutely follow the mathematical rules. 1. All the rules 2. The element-per-element operator 3. Ex1: graphing.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
Chapter 3 Arrays and Vectors
Knowing your math operation terms
Algebra Algebra.
Chapter 5-1 Exponents.
2.2 Introduction to Matrices
What is the dimension of the matrix below?
Math with Vectors I. Math Operations with Vectors.
Presentation transcript:

Array Operations ENGR 1181 MATLAB 4

Today's Learning Objectives After today’s class, students will be able to: Explain the meaning of element-by-element operations. Identify situations where the standard operators in MATLAB (when used with arrays) are reserved for linear algebra, which is not always element-by-element. Apply dot operators for the six cases where linear algebra is not element-by-element and therefore dot operators are needed to produce element-by-element calculations.

Scalar Math For scalar variables a and b : MATLAB has scalar math operations: >> a + b >> a – b >> a * b >> a / b >> a ^ b

Scalar–Vector Addition Define the vector v and the scalar c : >> v = [ 10 20 30 40 ] ; >> c = 4 ; Add them: >> v + c >> c + v ans = 14 24 34 44

Scalar - Vector Multiplication For the vector v and scalar c : >> v = [ 10 20 30 40 ] ; >> c = 4 ; Multiply them: >> c * v >> v * c ans = 40 80 120 160

Scalar - Vector Division Divide: >> v / c ans = 2.50 5.00 7.50 10.00

Scalar - Vector Division Divide: >> c / v >> c ./ v Error using / Matrix dimensions must agree. ans = 0.40 0.20 0.13 0.10

Scalar - Vector Exponents >> v ^ c Better: >> v .^ c ans = 10000 160000 810000 2560000 Error using ^ Inputs must be a scalar and a square matrix. To compute elementwise POWER, use POWER (.^) instead.

Scalar - Vector Math Summary For a scalar c and a vector v: Addition v + c or c + v Subtraction v – c or c – v Multiplication v * c or c * v or v.* c or c.* v Division v / c or c./ v or v./ c Exponent v.^ c or c.^ v

Vector–Vector Addition Define the vector x and the vector y : >> x = [ 10 20 30 40 ] ; >> y = [ 2 4 6 8 ] ; Add them: >> x + y >> y + x x and y must be the same length! ans = 12 24 36 48

Vector - Vector Multiplication x = [ 10 20 30 40 ]; y = [ 2 4 6 8 ]; Multiply: >> z = x * y ??? Error using ==> mtimes Inner matrix dimensions must agree!!!

Vector - Vector Multiplication x = [ 10 20 30 40 ] ; y = [ 2 4 6 8 ] ; Multiply two vectors element-by-element: >> z = x .* y z = 20 80 180 320

Vector - Vector Division x = [ 10 20 30 40 ] ; y = [ 2 4 6 8 ] ; Divide: >> x ./ y Also try >> y ./ x ans = 5 5 5 5 ans = 0.20 0.20 0.20 0.20

Vector - Vector Exponents y = [ 2 4 6 8 ] ; Exponent: >> x .^ y Also try: >> y .^ x ans = 4 16 64 256 ans = 4 16 36 64

Vector - Vector Math Summary For two vectors x and y : Addition x + y or y + x Subtraction x – y or y – x Multiplication x.* y or y.* x Division x./ y or y./ x Exponent x.^ y or y.^ x Always use the dot operator for Multiply, Divide, and Exponent

Example 1 Calculate y = 4x2 for x = 1, 2, 3 and 4 First define x >> x = [ 1 2 3 4 ]; Then calculate y >> y Which '.' is required below? y = 4.*x.^2 Required y = 4*x.^2 y = 4 16 36 64 y = 4 16 36 64

Example 2 a = 1 2 3 4 >> y = ((4*a.^2)+a)./(2+a) y = Calculate y = (4a2 + a)/(2+a) for a = 1, 2, 3 and 4 First define a : >> a = [ 1 2 3 4 ] a = 1 2 3 4 >> y = ((4*a.^2)+a)./(2+a) y = 1.6667 4.5000 7.8000 11.3333

Built - In Vector Functions MATLAB has built-in functions for vectors When v is a vector: max(v) Returns the largest element in v min(v) Returns the smallest element in v mean(v) Returns the average value of the elements in v sum(v) Returns the sum of the elements of v length(v) Returns the number of elements in v sort(v) Sorts the elements of v

Important Takeaways Know when to use the dot operator for Multiply, Divide, and Exponent. Always use a dot operator when appropriate and understand what you are trying to accomplish when you use it. Vector functions operate on all of the numbers in a vector or matrix.

Preview of Next Class Input and Output Inputting data into and out of programs GPA calculator example With and without use of vectors Inputting to a script file Output to command window

What’s Next? Review today’s Quiz #04 Open the in-class activity from the EEIC website and we will go through it together. Then, start working on MAT-04 homework. Before next class, you will read more detail about script files including global variables. There is also information on input and output (I/O) commands in MATLAB.