Chapter 2: Numeric, Cell, and Structure Arrays

Similar documents
Vectors. J.R. Wilson. September 27, 2018

Chapter 6: Vector Analysis

CITS2401 Computer Analysis & Visualisation

MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra

CITS2401 Computer Analysis & Visualisation

Linear Algebra V = T = ( 4 3 ).

Vector/Matrix operations. *Remember: All parts of HW 1 are due on 1/31 or 2/1

Review of Linear Algebra

Matrix Basic Concepts

CSCI 239 Discrete Structures of Computer Science Lab 6 Vectors and Matrices

Computational Foundations of Cognitive Science

I&C 6N. Computational Linear Algebra

1 Tensors and relativity

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

Lecture 3: Matrix and Matrix Operations

An Introduction to Matrix Algebra

Getting Started with Communications Engineering. Rows first, columns second. Remember that. R then C. 1

CHAPTER 8 CONSERVATION LAWS

L3: Review of linear algebra and MATLAB

Matlab Exercise 0 Due 1/25/06

Linear Algebra (Review) Volker Tresp 2017

Determinant: 3.2 Evaluation of Determinant with Elementary

Linear Algebra (Review) Volker Tresp 2018

MET 4301 LECTURE SEP17

Lecture 3 Linear Algebra Background

Elementary Row Operations on Matrices

Identity Matrix: EDU> eye(3) ans = Matrix of Ones: EDU> ones(2,3) ans =

Moment of a force (scalar, vector ) Cross product Principle of Moments Couples Force and Couple Systems Simple Distributed Loading

Numerical Methods Lecture 2 Simultaneous Equations

Applied Linear Algebra in Geoscience Using MATLAB

TOPIC 2 Computer application for manipulating matrix using MATLAB

Matrices. Chapter Definitions and Notations

For those who want to skip this chapter and carry on, that s fine, all you really need to know is that for the scalar expression: 2 H

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

Linear Algebra Review. Fei-Fei Li

Matrix Arithmetic. a 11 a. A + B = + a m1 a mn. + b. a 11 + b 11 a 1n + b 1n = a m1. b m1 b mn. and scalar multiplication for matrices via.

Lesson 1: Inverses of Functions Lesson 2: Graphs of Polynomial Functions Lesson 3: 3-Dimensional Space

Vectors for Physics. AP Physics C

Vectors. J.R. Wilson. September 28, 2017

Vectors in Physics. Topics to review:

Matrices and Vectors

SECTION 2: VECTORS AND MATRICES. ENGR 112 Introduction to Engineering Computing

Vectors and Matrices Lecture 2

Chapter 1. Units, Physical Quantities, and Vectors

This appendix provides a very basic introduction to linear algebra concepts.

MATLAB BASICS. Instructor: Prof. Shahrouk Ahmadi. TA: Kartik Bulusu

PHYS102 - Gauss s Law.

A Introduction to Matrix Algebra and the Multivariate Normal Distribution

MA 102 (Multivariable Calculus)

Elementary Linear Algebra

A = 3 B = A 1 1 matrix is the same as a number or scalar, 3 = [3].

Remark 3.2. The cross product only makes sense in R 3.

Numerical Methods Lecture 2 Simultaneous Equations

A VERY BRIEF LINEAR ALGEBRA REVIEW for MAP 5485 Introduction to Mathematical Biophysics Fall 2010

Math 276, Spring 2007 Additional Notes on Vectors

Arrays: Vectors and Matrices

F A C U L T Y O F E D U C A T I O N. Physics Electromagnetism: Induced Currents Science and Mathematics Education Research Group

Two matrices of the same size are added by adding their corresponding entries =.

Dr. Allen Back. Sep. 8, 2014

Vector Algebra II: Scalar and Vector Products

Rotational motion of a rigid body spinning around a rotational axis ˆn;

Mechanics, Heat, Oscillations and Waves Prof. V. Balakrishnan Department of Physics Indian Institute of Technology, Madras

MATH 2030: MATRICES ,, a m1 a m2 a mn If the columns of A are the vectors a 1, a 2,...,a n ; A is represented as A 1. .

Relationships Between Planes

Chapter 2 - Vector Algebra

CSC 470 Introduction to Computer Graphics. Mathematical Foundations Part 2

Mathematics Revision Questions for the University of Bristol School of Physics

Mathematics and Signal Processing for Biomechanics

Introduction to Computational Neuroscience

Part I, Number Systems CS131 Mathematics for Computer Scientists II Note 3 VECTORS

Linear Algebra March 16, 2019

Tute UV2 : VECTORS 1

VECTORS AND MATRICES

CS 246 Review of Linear Algebra 01/17/19

We are already familiar with the concept of a scalar and vector. are unit vectors in the x and y directions respectively with

Matrices. A matrix is a method of writing a set of numbers using rows and columns. Cells in a matrix can be referenced in the form.

Math 302 Outcome Statements Winter 2013

1. Vectors.

MATH1012 Mathematics for Civil and Environmental Engineering Prof. Janne Ruostekoski School of Mathematics University of Southampton

Overview. Motivation for the inner product. Question. Definition

[ Here 21 is the dot product of (3, 1, 2, 5) with (2, 3, 1, 2), and 31 is the dot product of

POLI270 - Linear Algebra

Basic Math Review for CS4830


Engineering Mechanics Statics

Lecture 6: Geometry of OLS Estimation of Linear Regession

ECE 102 Engineering Computation

Lecture 35: The Inertia Tensor

CSE 167: Introduction to Computer Graphics Lecture #2: Linear Algebra Primer

Please Visit us at:

Matrices. Math 240 Calculus III. Wednesday, July 10, Summer 2013, Session II. Matrices. Math 240. Definitions and Notation.

Matrices BUSINESS MATHEMATICS

The Cross Product. MATH 311, Calculus III. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan The Cross Product

CHAPTER 7 ELECTRODYNAMICS

FF505 Computational Science. Matrix Calculus. Marco Chiarandini

Math 360 Linear Algebra Fall Class Notes. a a a a a a. a a a

Review from Bootcamp: Linear Algebra

22.3. Repeated Eigenvalues and Symmetric Matrices. Introduction. Prerequisites. Learning Outcomes

x n -2.5 Definition A list is a list of objects, where multiplicity is allowed, and order matters. For example, as lists

Fluid Mechanics Prof. S. K. Som Department of Mechanical Engineering Indian Institute of Technology, Kharagpur

Transcription:

Chapter 2: Numeric, Cell, and Structure Arrays Topics Covered: Vectors Definition Addition Multiplication Scalar, Dot, Cross Matrices Row, Column, Square Transpose Addition Multiplication Scalar-Matrix, Matrix-Matrix Element-by-Element Operations Multiplication, Division, Exponentiation, Vectorized Functions Array Addressing

Vectors A Scalar is a number that has magnitude but no direction (Temperature reading on a thermometer, pressure reading on a pressure gage) A Vector has both magnitude and direction. Vectors are used by engineers to represent position, velocity, acceleration, force, torque, angular velocity, angular acceleration, linear momentum, angular momentum, heat flux, magnetic flux, etc.

The Vector a is composed of three Cartesian Components: a = a x i + a y j + a z k i, j, and k are Unit Vectors in the x, y, z directions. The Length of a Unit Vector is one. The Length of the Vector a is called its Magnitude: a = a 2 x + a 2 y + a2 z Vectors are represented in MATLAB as: a = a x, a y, a z or a x a y a z

Open up a new MATLAB Script File:

Vector Addition: Add the corresponding Components of the two Vectors: a + b = a x, a y, a z + b x, b y, b z a + b = (a x +b x ), (a y + b y ), (a z + b z ) a b = (a x b x ), (a y b y ), (a z b z ) Modify and run the Script File as follows:

Vector Multiplication Scalar Vector: Distribute the Scalar to each Component of the Vector: c a = ca x, ca y, ca z Modify and run the Script File as follows:

Vector Dot Product Vector Vector: Sum of the products of the corresponding Components of the two Vectors. a b = a b cos θ = Scalar a b = b a = a x b x + a y b y + a z b z Modify and run the Script File as follows:

Vector Cross Product Vector Vector: Results in a Vector Normal (Perpendicular) to the plane defined by the two vectors being crossed. a b = ( a b sin θ) n = Vector n is the Unit Vector Normal to the Plane. a b = b a = i j k a x a y a z b x b y b z Determinant Method a b = a y b z a z b y i a x b z a z b x j + a x b y a y b x k

Modify and run the Script File as follows:

Matrices A Matrix is a rectangular Array of numbers arranged in Rows and Columns. The individual numbers in a Matrix are called Elements. A = A 11 A 12 A 13 A 21 A 22 A 23 A 31 A 32 A 33 Row 1 Column 1 A Row Column : A 23 = Number in the Second Row, Third Column In MATLAB, use a Comma to separate Columns; use a Semi-Colon to separate Rows: A = [A 11, A 12, A 13 ; A 21, A 22, A 23 ; A 31, A 32, A 33 ]

Modify and run the Script File as follows:

Row Vector: A Matrix with one Row, multiple Columns B = B 11, B 12, B 13 Column Vector: A Matrix with one Column, multiple Rows C = C 11 C 21 C 31 In MATLAB, create a Column Vector by using Semi-Colons to separate Rows C = C 11 ; C 12 ; C 13 Square Matrix: Number of Rows = Number of Columns D = D 11 D 12 D 21 D 22

A Vector can be Transposed by switching the Rows and Columns. A = A 11 A 12 A 13 A 21 A 22 A 23 A T = A 31 A 32 A 33 A 11 A 21 A 31 A 12 A 22 A 32 A 13 A 23 A 33 Modify and run the Script File as follows:

Matrix Addition: The Size of the two Matrices must be the same: 2 2 + 2 2 = (2 2) (Two Rows Two Columns) D + F = D 11 D 12 D 21 D 22 + F 11 F 12 F 21 F 22 D + F = (D 11+F 11 ) (D 12 +F 12 ) (D 21 +F 21 ) (D 22 +F 22 ) Modify and run the Script File as follows:

Scalar Matrix Multiplication: The Scalar is Distributed to all of the Elements of the Matrix: ca = ca 11 ca 12 ca 13 ca 21 ca 22 ca 23 ca 31 ca 32 ca 33 Modify and run the Script File as follows:

Matrix Matrix Multiplication: The Size of the two Matrices Can Be the Same: 2 2 2 2 = (2 2) Modify and run the Script File as follows: D F = D 11 D 12 D 21 D 22 F 11 F 12 F 21 F 22 D F = (D 11F 11 + D 12 F 21 ) (D 11 F 12 + D 12 F 22 ) (D 21 F 21 + D 22 F 11 ) (D 21 F 12 + D 22 F 22 )

Matrix Matrix Multiplication: The Sizes of the two Matrices Can Be Different: The Inner Sizes Must be the Same; the Outer Sizes Can be Different. Inner Sizes 3 2 2 3 = (3 3) Outer Sizes K L = K 11 K 12 K 21 K 22 K 31 K 32 L 11 L 12 L 13 L 21 L 22 L 23 = K 11 L 11 + K 12 L 21 K 11 L 12 + K 12 L 22 K 11 L 13 + K 12 L 23 K 21 L 11 + K 22 L 21 K 21 L 12 + K 22 L 22 K 21 L 13 + K 22 L 23 K 31 L 11 + K 32 L 21 K 31 L 12 + K 32 L 22 K 31 L 13 + K 32 L 23

Modify and run the Script File as follows: What Happens when you Reverse the Order of Multiplication? Try it!

2 3 3 2 = (2 2) L K = L 11 L 12 L 13 L 21 L 22 L 23 K 11 K 12 K 21 K 22 K 31 K 32 = L 11K 11 + L 12 K 21 + L 13 K 31 L 11 K 12 + L 12 K 22 + L 13 K 32 L 21 K 11 + L 22 K 21 + L 23 K 31 L 21 K 12 + L 22 K 22 + L 23 K 32 In General, Inner Sizes Must be Equal n m m p = (n p) Outer Sizes Can Be Different

Another method to calculate the Dot Product of two vectors is to use Matrix Multiplication: B = B 11, B 12, B 13 C = C 11, C 12, C 13 B C = B 11 B 12 B 13 Verify this using MATLAB! C 11 C 21 C 31 Let: B = 1, 2, 3 C = 4, 5, 6

Element Element Multiplication: Element-by-Element Multiplication is often used in engineering calculations. It is defined only for arrays that have the same size. D. F = D 11 D 12 D 21 D 22. F 11 F 12 F 21 F 22 D. F = (D 11F 11 ) (D 12 F 12 ) (D 21 F 21 ) (D 22 F 22 )

Element Element Division: Element-by-Element Division is also defined only for arrays that have the same size. D./F = D 11 D 12 D 21 D 22./ F 11 F 12 F 21 F 22 D./F = (D 11/F 11 ) (D 12 /F 12 ) (D 21 /F 21 ) (D 22 /F 22 )

Element Element Exponentiation: Element-by-Element Exponentiation is also defined only for arrays that have the same size. D. ^F = D 11 D 12 D 21 D 22. ^ F11 F 12 F 21 F 22 D. ^F = (D 11^F 11 ) (D 12^F 12 ) (D 21^F 21 ) (D 22^F 22 )

Vectorized Functions: When you use functions like sin(x), atan(x) and exp(x) on vectors, the results of the functions become vectors also. These are called Vectorized Functions. When multiplying or dividing these functions, you must use Element-by-Element Operations.

Vectorized Functions:

Vectorized Functions:

Vectorized Functions:

Vectorized Functions:

Vectorized Functions:

Array Addressing Now that you know how to create arrays, you need to be able to use specific elements, or rows, or columns in calculations. This is called Array Addressing. The Colon operator allows us to select individual elements, rows, columns, or parts of arrays.

Problem 2.1: a. Use two methods to create the vector x having 100 regularly spaced values starting at 5 and ending at 28. b. Use two methods to create the vector x having a regular spacing of 0.2 starting at 2 and ending at 14. Start by looking at a simpler scenario, where three regularly spaced values are desired (n = 3): 5 28 Δx x = 28 5 3 1 = 11.5 5 + 11.5 = 16.5 16.5 + 11.5 = 28 In General, x = x max x min n 1

Problem 2.1: a. Use two methods to create the vector x having 100 regularly spaced values starting at 5 and ending at 28. b. Use two methods to create the vector x having a regular spacing of 0.2 starting at 2 and ending at 14.