(24) Linear Algebra

(24) Linear Algebra - ComputersinEngineering COMP208...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Computers in Engineering COMP 208 Linear Algebra Nathan Friedman and Michael A. Hawker
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Representing Vectors A vector is a sequence of numbers (the  components of the vector) If there are n numbers, the vector is said to be of  dimension n To represent a vector in C, we use an array of  size n, indexed from 0 to n-1 In Fortran we use an array indexed from 1 to n Nov. 29th, 2007 Linear Algebra 2
Background image of page 2
Vector Operations Scaling Multiply each element by a given scalar  factor Adding and Subtracting Given two vectors of the same dimension  add the components to get a new vector  of the same dimension Nov. 29th, 2007 Linear Algebra 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Vector Operations (cont) Dot Product Sum the Products of Vector Components Vector Norm Length of the Vector, Square-root of the sum of  squares of Components Nov. 29th, 2007 Linear Algebra 4
Background image of page 4
Representing Matrices A matrix with m rows and n columns can be  represented as a two dimensional array in C (or  Fortran). In C the declaration could be double voltage[m][n]; The first dimension is the number of rows and the  second the number of columns A specific value in row i, column j is referenced as  voltage[i][j] Nov. 29th, 2007 Linear Algebra 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Initialization We can initialize a matrix (or any array) when it is  declared: int val[3][4] = {{8,16,9,24}, {3,7,19,25}, {42,2,4,12}}; Nov. 29th, 2007 Linear Algebra 6
Background image of page 6
Row Major Ordering What happens if we write int val[3][4] = {{8,16,9,24,3,7,19,25,42,2,4,12}}; We begin filling in values starting with  v[0][0]   and continue.  If the array is stored in row major order, this has  the same effect as the previous example Nov. 29th, 2007 Linear Algebra 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Implementing Row Major Order We can simulate a matrix using a one  dimensional array by taking the two indices and  finding the position in row major order. We have to know how many columns there are,  that is the number of elements in each row. int in2d(int row, int col, int n){ return col + row * n; } Nov. 29th, 2007 Linear Algebra 8
Background image of page 8
Simulating Matrices in One Dimension In the previous example we showed how to simulate a  matrix by a one dimensional vector. This may be done in some applications to make highly  computational intensive programs more efficient We could also simulate a matrix with a one dimensional  array that stores the values in column major order Used with other Data Structures as well Nov. 29th, 2007 Linear Algebra 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
**, What about [][]? We can't use [][] in our function arguments:
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2010 for the course COMP COMP 206 taught by Professor Vybihal during the Spring '04 term at McGill.

Page1 / 36

(24) Linear Algebra - ComputersinEngineering COMP208...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online