Haas MFE SAS Workshop Lecture 3:

Slides:



Advertisements
Similar presentations
Haas MFE SAS Workshop Lecture 3:
Advertisements

4.1 Introduction to Matrices
Matrices A matrix is a rectangular array of quantities (numbers, expressions or function), arranged in m rows and n columns x 3y.
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.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
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.
EGR 106 – Week 3 – More on Arrays Brief review of last week Additional ideas: – Special arrays – Changing an array – Some array operators – Character arrays.
INDR 262 INTRODUCTION TO OPTIMIZATION METHODS LINEAR ALGEBRA INDR 262 Metin Türkay 1.
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.
Matrix Definition A Matrix is an ordered set of numbers, variables or parameters. An example of a matrix can be represented by: The matrix is an ordered.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
Inverting Matrices Determinants and Matrix Multiplication.
Chapter 2 Systems of Linear Equations and Matrices Section 2.4 Multiplication of Matrices.
ECON 1150 Matrix Operations Special Matrices
Little Linear Algebra Contents: Linear vector spaces Matrices Special Matrices Matrix & vector Norms.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
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.
SAS Interactive Matrix Language Computing for Research I Spring 2012 Ramesh.
Haas MFE SAS Workshop Lecture 3: Peng Liu Haas School.
Matrices.
Matrices Matrices A matrix (say MAY-trix) is a rectan- gular array of objects (usually numbers). An m  n (“m by n”) matrix has exactly m horizontal.
2009/9 1 Matrices(§3.8)  A matrix is a rectangular array of objects (usually numbers).  An m  n (“m by n”) matrix has exactly m horizontal rows, and.
4.4 Identify and Inverse Matrices Algebra 2. Learning Target I can find and use inverse matrix.
Prepared by Deluar Jahan Moloy Lecturer Northern University Bangladesh
Chapter 2 Creating Arrays Legend: MATLAB command or syntax : Blue MATLAB command OUTPUT : LIGHT BLUE.
Copyright © 2011 Pearson Education, Inc. Solving Linear Systems Using Matrices Section 6.1 Matrices and Determinants.
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.
Matrices: Simplifying Algebraic Expressions Combining Like Terms & Distributive Property.
Review of Matrix Operations Vector: a sequence of elements (the order is important) e.g., x = (2, 1) denotes a vector length = sqrt(2*2+1*1) orientation.
Programming in R Managing Variables. Managing variables in R In this session I will show you how to: Rename, drop and keep variables Create new variables.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
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.
Section 9-1 An Introduction to Matrices Objective: To perform scalar multiplication on a matrix. To solve matrices for variables. To solve problems using.
1 An Introduction to R © 2009 Dan Nettleton. 2 Preliminaries Throughout these slides, red text indicates text that is typed at the R prompt or text that.
MATRICES Operations with Matrices Properties of Matrix Operations
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.
Manipulating MATLAB Vector, Matrices 1. Variables and Arrays What are variables? You name the variables (as the programmer) and assign them numerical.
Linear System of Simultaneous Equations Warm UP First precinct: 6 arrests last week equally divided between felonies and misdemeanors. Second precinct:
Chapter 1 Section 1.6 Algebraic Properties of Matrix Operations.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Matrices. Matrix - a rectangular array of variables or constants in horizontal rows and vertical columns enclosed in brackets. Element - each value in.
MATRICES. Introduction Matrix algebra has several uses in economics as well as other fields of study. One important application of Matrices is that it.
Matrices. Variety of engineering problems lead to the need to solve systems of linear equations matrixcolumn vectors.
Matrices and systems of Equations. Definition of a Matrix * Rectangular array of real numbers m rows by n columns * Named using capital letters * First.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
Matlab Workshop Getting Started.
Linear Algebra review (optional)
Linear Algebra Lecture 2.
Review of Matrix Operations
1.5 Matricies.
Chapter 2 Creating Arrays.
Introduction to Matrices
Matrix Operations.
Matrices.
Five Basic Programming Elements
Introduction to Matrices
Appendix D: SAS PROC IML
2.2 Introduction to Matrices
Arrays and Matrices in MATLAB
Array Creation ENGR 1181 MATLAB 02.
Matrices.
Linear Algebra review (optional)
Matrices.
Matrices.
Matrix Operations Ms. Olifer.
Matrices and Determinants
Presentation transcript:

Haas MFE SAS Workshop Lecture 3: Peng Liu http://faculty.haas.berkeley.edu/peliu/computing Haas School of Business, Berkeley, MFE 2006

Peng Liu http://faculty.haas.berkeley.edu/peliu/computing SAS IML Peng Liu http://faculty.haas.berkeley.edu/peliu/computing Haas School of Business, Berkeley, MFE 2006

PROC IML - What OUTLINES Defining Matrix Creating Matrix Combining Matrix Matrix Algebra (Function, Reduction Operators) Read-In SAS data sets Create SAS data sets Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 3

Defining and Referencing matrices PROC IML; RESET PRINT; A=3; B={1 2 3}; *row vector; C={1,2,3}; *column vector; D={1 2 3, 4 5 6};*2 X 3 matrix; QUIT; PROC IML; D={1 2 3, 4 5 6}; E1=D[,2]; E2=D[1,]; E3=D[2,3]; E4=D[{1 3},{2 3}]; PRINT D E1 E2 E3 E4; QUIT; Begin with PROC IML; end with QUIT; RESET PRINT produce all output; otherwise specify what you want to PRINT , but you have to assign first. Use curly brackets { } to create vector or matrix Use square bracket [] to refer to elements E4=D[{1 3},{2 3}]; assigns submatrix to E4 consisting 1,3 rows and 2,3 columns of matrix D Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 4

Creating matrices PROC IML; RESET PRINT; index=1:5; rindex=5:1; vars='X1':'X8'; series = do(0,84,12); aa = I(6); bb = j(5,5,0); cc = j(6,1); dd = diag({1 2 4}); ee = diag({1 2,3 4}); QUIT; Index operator : creates a row vector of consecutive integers or character strings Do function creates series with any increment Identity matrix: I(size) Constant matrix J(nrow, ncol, value) Diagonal matrices: DIAG(VECTOR) Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 5

Combining matrices Transpose operation using t() PROC IML; RESET PRINT; b={1 2 3 4}; bt=t(b); c={1 2 3 4,2 4 6 8, 3 9 7 5 ,9 8 7 6}; i1=c//b;i2=c||bt; QUIT; Transpose operation using t() "//" and ||" concatenates matrices vertically and horizontally respectively Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 6

Matrix Algebra - Basics Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 7

Matrix Algebra – Matrix functions Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 8

Matrix Algebra – Matrix Reduction Operators Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 9

Read SAS data sets PROC IML; RESET PRINT; USE MFE.LOAN; READ ALL INTO m WHERE(state='CA'); QUIT; *READ ALL VAR{id term rate} INTO m; USE …; specify which SAS data set is to be used READ ALL INTO …; converts SAS data set into a matrix. READ ALL only read numerical variables; Use VAR{term rate} option to select variables Use WHERE to subset data. Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 10

Create SAS data sets PROC IML; RESET PRINT; seed=J(3,3,9); r = ranuni(seed); CREATE data FROM r; APPEND FROM r; QUIT; J function build 3 by 3 matrix with seed=9 for each element CREATE … FROM opens the new SAS data set APPEND FROM writes to the SAS data set Output dataset has default column names COL1 COL2… You can rename by option [COLNAME = “R”] Haas School of Business, Berkeley, MFE 2006 Peng Liu AND Alexander Vedrashko 11