Lecture 2 Mathcad basics and Matrix Operations

Similar documents
Lecture 2 Mathcad Basics

CGN Computer Methods

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

PTC Mathcad Prime 3.0 Keyboard Shortcuts

Matrix Multiplication

3.2 Matrix Multiplication

Typical Linear Equation Set and Corresponding Matrices

Section V.3: Dot Product

Solution to Homework 2

Beginner s Matlab Tutorial

Lecture 2 Matrix Operations

Lecture Notes 2: Matrices as Systems of Linear Equations

Excel Basics By Tom Peters & Laura Spielman

[1] Diagonal factorization

Matrix Algebra in R A Minimal Introduction

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

The Projection Matrix

Solving Mass Balances using Matrix Algebra

Linear Algebra and TI 89

A linear combination is a sum of scalars times quantities. Such expressions arise quite frequently and have the form

Using Casio Graphics Calculators

a(1) = first.entry of a

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

Matrices 2. Solving Square Systems of Linear Equations; Inverse Matrices

MATHEMATICS FOR ENGINEERS BASIC MATRIX THEORY TUTORIAL 2

1 Introduction to Matrices

How long is the vector? >> length(x) >> d=size(x) % What are the entries in the matrix d?

Solving simultaneous equations using the inverse matrix

Notes on Orthogonal and Symmetric Matrices MENU, Winter 2013

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)

DETERMINANTS TERRY A. LORING

CS3220 Lecture Notes: QR factorization and orthogonal transformations

Rotation Matrices and Homogeneous Transformations

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

K80TTQ1EP-??,VO.L,XU0H5BY,_71ZVPKOE678_X,N2Y-8HI4VS,,6Z28DDW5N7ADY013

EXCEL SOLVER TUTORIAL

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

Excel supplement: Chapter 7 Matrix and vector algebra

Linear Programming. March 14, 2014

Linear Algebra Review. Vectors

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

8.2. Solution by Inverse Matrix Method. Introduction. Prerequisites. Learning Outcomes

Here are some examples of combining elements and the operations used:

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Introduction to Matrix Algebra

Question 2: How do you solve a matrix equation using the matrix inverse?

Estimating a market model: Step-by-step Prepared by Pamela Peterson Drake Florida Atlantic University

Doing Multiple Regression with SPSS. In this case, we are interested in the Analyze options so we choose that menu. If gives us a number of choices:

Introduction to Matrices

Math 1050 Khan Academy Extra Credit Algebra Assignment

PLOTTING DATA AND INTERPRETING GRAPHS

Brief Introduction to Vectors and Matrices

Vectors 2. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Lecture 3: Finding integer solutions to systems of linear equations

Introduction to Matrices for Engineers

28 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. v x. u y v z u z v y u y u z. v y v z

DERIVATIVES AS MATRICES; CHAIN RULE

1.2 Solving a System of Linear Equations

Solutions to Math 51 First Exam January 29, 2015

MATLAB Workshop 3 - Vectors in MATLAB

Syntax Description Remarks and examples Also see

Linear Algebra: Vectors

Linear Algebra Notes for Marsden and Tromba Vector Calculus

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

MATLAB Basics MATLAB numbers and numeric formats

Using Microsoft Excel Built-in Functions and Matrix Operations. EGN 1006 Introduction to the Engineering Profession

Solving Systems of Linear Equations Using Matrices

Matrix Differentiation

Introduction to Matlab

CBE 6333, R. Levicky 1. Tensor Notation.

Chapter 4. Spreadsheets

Vector Math Computer Graphics Scott D. Anderson

Summary of important mathematical operations and formulas (from first tutorial):

Determine If An Equation Represents a Function

Torgerson s Classical MDS derivation: 1: Determining Coordinates from Euclidean Distances

Review Jeopardy. Blue vs. Orange. Review Jeopardy

Math 2524: Activity 3 (Excel and Matrices, continued) Fall 2002

Situation Analysis. Example! See your Industry Conditions Report for exact information. 1 Perceptual Map

5 Homogeneous systems

A Primer on Index Notation

Factoring. Factoring Monomials Monomials can often be factored in more than one way.

Excel Formatting: Best Practices in Financial Models

Tool 1. Greatest Common Factor (GCF)

10. Comparing Means Using Repeated Measures ANOVA

Similarity and Diagonalization. Similar Matrices

WEEK #3, Lecture 1: Sparse Systems, MATLAB Graphics

Continued Fractions and the Euclidean Algorithm

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

To give it a definition, an implicit function of x and y is simply any relationship that takes the form:

LS.6 Solution Matrices

8 Square matrices continued: Determinants

AP Computer Science Java Mr. Clausen Program 9A, 9B

Vectors Math 122 Calculus III D Joyce, Fall 2012

Tutorial for the TI-89 Titanium Calculator

1 Review of Least Squares Solutions to Overdetermined Systems

Excel 2010: Create your first spreadsheet

Multiple regression - Matrices

Dynamic Programming. Lecture Overview Introduction

Transcription:

Lecture 2 Mathcad basics and Matrix Operations Announcements No class or lab Wednesday, 8/29/01 I will be posting a lab worksheet on the web site on Tuesday for you to work through on your own. Operators + Addition, - Subtraction, * Multiplication, / Division, ^ Power ( ) Specify evaluation order Order of Operations ( ) ^ highest level, first priority * / next priority level + - last operations to be performed y := 2 x := 3 * y^2 x = 12 y := 2 x := (3*y)^2 x = 36 y := 2 x := 3 * y + 2 x = 8 z := 3*6+6*2/4 z = 21 x := 5^2/2 x = 12.5 Matrix operations: Mathcad is designed to be a tool for quick and easy manipulation of matrix forms of data. We ve seen the matrix before in Lecture 1 as a 2-D array. That is, many pieces of information are stored under a single name. Different pieces of information are then retrieved by pointing to different parts of the matrix by row and column. Here we will learn some basic matrix operations: Adding and Subtracting, Transpose, Multiplication. Adding matrices Add two matrices together is just the addition of each of their respective elements. If A and B are both matrices of the same dimensions (size), then Lecture 2 Mathcad basics and Matrix Operations page 11 of 18

C := A + B produces C, where the i th row and j th column are just the addition of the elements (numbers) in the i th row and j th column of A and B Given:!!" #, and " ' ( ) $%!! *!+!' so that the addition is : #,-!. " " $!!!#!% '" The Mathcad commands to perform these matrix assignments and the addition are: A := Ctrl-M (choose 2 x 3) 1 3 5 7 9 11 B := Ctrl-M (choose 2 x 3) 2 4 6 8 10 12 C := A + B C = Rule: A, B, and C must all have the same dimensions Transpose Transposing a matrix means swapping rows and columns of a matrix. No matrix dimension restrictions Some examples: 1-D! #'%,! $ # ' 1x3 becomes ==> 3x1 % 2-D " */! 0 (/# 0 $/), " $ */! "/' 0 (/# "/! 2x3 becomes ==> 3x2 "/' "/! "/% 0 $/) "/% In general "% (, ) " $ (, %) In Mathcad, The transpose is can be keystroked by Ctrl - 1 (the number one) " #")' %*($ B Ctrl-1 = '() #% "* )( '$ Lecture 2 Mathcad basics and Matrix Operations page 12 of 18

Multiplication Multiplication of matrices is not as simple as addition or subtraction. It is not an element by element multiplication as you might suspect it would be. Rather, matrix multiplication is the result of the dot products of rows in one matrix with columns of another. Consider: C := A * B matrix multiplication gives the i th row and k th column spot in C as the scalar results of the dot product of the i th row in A with the k th column in B. In equation form this looks like: 2,34,536789:,;9,< # %, *! %,,1,", *! Let s break this down in a step-by-step example: Step 1: Dot Product (a 1-row matrix times a 1-column matrix) The Dot product is the scalar result of multiplying one row by one column ) '#" 1 * '1).#1*."1$ $" DOT PRODUCT OF ROW AND COLUMN 1x1 1x3 $ 3x1 Rule: 1) # of elements in the row and column must be the same 2) must be a row times a column, not a column times a row Step 2: general matrix multiplication is taking a series of dot products each row in pre-matrix by each column in post-matrix # )!(' 1 *!'!1#.(1*.'1!+,,,,!1).(1!'.'1!! #$ $) %"$ %1#."1*.$1!+,,,,%1)."1!'.$1!!!"%!)$!+!! 2x3 3x2 2x2 C(i,k) is the result of the dot product of row i in A with column k in B Matrix Multiplication Rules: 1) The # of columns in the pre-matrix must equal # of rows in post-matrix inner matrix dimensions must agree 2) The result of the multiplication will have the outer dimensions # rows in pre-matrix by # columns in post-matrix Lecture 2 Mathcad basics and Matrix Operations page 13 of 18

For this example, apply rules C := A * B A is nra x nca (# rows in a by # columns in a) B is nrb x ncb Rule 1 says: nca = nrb or else we can t multiply (can t take dot products with different number of terms in row and column) Rule 2 says: C will be of size nra x ncb result C has outer dimensions (+',,,(-',1,(+.,,,(-. inner dimensions must agree How to perform matrix multiplication in Mathcad??? Easy A := [4 5; 2 1] B := [9 1; 6 12] C := A*B Note: Now that we know how to enter a matrix into Mathcad, I ll use a shortcut notation for these notes as applied above, where: A := [4 5; 2 1] means a 2 x 2 array where the ; indicates the start of the next row. The ; is not actually used in Mathcad for this purpose, its just a shorthand notation that I ll use for these notes. D := [12 34 56; 45 89 9] is a 2 x 3 matrix using this notation Note: If inner matrix dimensions don t match, Mathcad can t perform the operation since it violates the rules of matrix multiplication, and you ll get an error that says: the number of rows and or columns in these arrays do not match Lecture 2 Mathcad basics and Matrix Operations page 14 of 18

example: Let s try to multiply a 2x3 by another 2x3 (rules say we can t do this) A := [3 4 1 ; 0 4 9]; B := [2 9 5 ; 9 4 5]; C := A * B Mathcad will tell you: the number of rows and or columns in these arrays do not match and won t provide an answer Since the # of columns in A was not equal to # of rows in B, we can t multiply A * B IMPORTANT: Another example: Say we create a 1-D vector x with the following: x := [2 4 9 5 2]; Now say we want to square each number in x. It would seem natural to do this: y := x^2 But Mathcad tells us: This Matrix must be square. It should have the same number of rows as columns Note that y : = x^2 is the same as saying y := x*x Mathcad by default will always interpret any multiplication as a standard dot product type matrix multiplication, thus we can t take a dot product of two row vectors, since rules of matrix multiplication are violated in this case. The exception to this default assumption in Mathcad is if the vector is a column instead of a row. In that case, Mathcad will assume you want to square each element in the vector rather that apply standard matrix multiplication. If we just want to square the numbers in x, we can do this: y = x Ctrl-1 shift ^2 This first transposes the row vector into a column vector, then squares the elements in the vector Try this out a:= ( 2 5 4) ( ) 2 4 a T = 25 16 Lecture 2 Mathcad basics and Matrix Operations page 15 of 18

Practice matrix operations on the following examples. List the size of the resulting matrix first. then perform the operations by hands. Use Mathcad to confirm each of your answers. %!'# 1 ' * " %$ ") $! ' ( ) *!+!' ( % $ 1 '!* (" '! 1 *$ %) (%* $ 1 '$!!(% *)( 1 "+ %" ($ ($ #" $. 1!+ ' $ *% +! ) " # We will consider the use of matrices to solve a number of different problems in the numerical methods portion of the course. Lecture 2 Mathcad basics and Matrix Operations page 16 of 18

Fundamental Program Structure Labeling the program using comments program title student information program summary executable statements program input (load data from external files, assignment statements, etc.) perform operations needed (sequential execution, loops, etc.) display program output (graphs, numbers, output files, etc.) intersperse comments to explain program Example program #1 K., CGN 3421, August 27, 2001 This program demonstrates basic program structure INPUT SECTION x:= 2 15 8 4 CALCULATION SECTION ( ) 2 y := x + x CREATE scalar y as a function 1 4 of x1 and x4 40 z:= x 2 + y 261 CREATE z vector from x and y z = 100 NOTE that x^2 operates on each value in x 52 OUTPUT SECTION 300 z 200 100 0 0 5 10 15 x graph of z vs. x NOTE that the plot plots the x values in order of appearance it does not reorder and sort Lecture 2 Mathcad basics and Matrix Operations page 17 of 18

Vector operations Note in the previous example that z was created from the vector x and the scalar y. Mathcad knew how to handle the combination based on its default assumptions, and the resultant variable z is a vector. This is an example of a vector operation. That is, we did not have to write an algorithm to explicitly calculate each of the values in z one at a time. However, we will see later that it is important to know how to operate on one element at a time within a vector or matrix. In the previous example, we could have used a for loop to explicitly calculate each element of z, one at a time. Simply replace the Calculation section with the following CALCULATION SECTION ( ) 2 y := x + 1 x CREATE scalar y as a function 4 of x1 and x4 z := for i zz zz i 1.. length() x ( x i ) 2 + y z = 40 261 100 52 CREATE z vector from x and y Another example of vector operation Plot the following function over the range / '. ", 0 ', '. +/', ", 0 #!+ yx ():= 2+ 3x 2x 2 + 0.2x 3 CREATE FUNCTION x:= 5, 4.5.. 10 CREATE Range Vector 50 yx ( ) 0 50 PLOT of function 100 5 0 5 10 x Lecture 2 Mathcad basics and Matrix Operations page 18 of 18