lecture_22_s2005

lecture_22_s2005 - 1.00 Lecture 22 Matrices Reading for...

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

View Full Document Right Arrow Icon
1.00 Lecture 22 Matrices Reading for next time: Numerical Recipes, pp. 37-42 Matrices Matrix is 2-D array of m rows by n columns In math notation, we use index 1, … m and 1, … n. In Java, we usually use index 0, … m-1 and 0, …n-1 They often represent a set of linear equations: a 00 x 0 + a 01 x 1 + a 02 x 2 + … + a 0,n-1 x n-1 = b 0 a 10 x 0 + a 11 x 1 + a 12 x 2 + … + a 1,n-1 x n-1 = b 1 a m-1,0 x 0 + a m-1,1 x 1 + a m-1,2 x 2 + … + a m-1,n-1 x n-1 = b m-1 n unknowns x are related by m equations Coefficients a are known, as are right hand side b …… a m-1,n-1 a m-1,3 … a m-1,2 a m-1,1 a m-1,0 a 2n-1 a 23 … a 22 a 21 a 20 a 1n-1 a 13 … a 12 a 11 a 10 a 0n-1 a 03 … a 02 a 01 a 00
Background image of page 1

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

View Full DocumentRight Arrow Icon
Matrices, p.2 In this lecture we cover basic matrix representation and manipulation Used most often to prepare matrices for use in solving linear systems, which we cover in next lecture Java has 2-D arrays, declared as, for example double[][] squareMatrix= new double[5][5]; But there are no built-in methods for them So, it’s helpful to create a Matrix class: Create methods to add, subtract, multiply, form identity matrix, etc. Sparse matrices are handled differently: Almost all large matrices are extremely sparse (99%+ of entries are zeros) Store (i, j, value) in a list or 1-D array or other data structure 2-D Arrays data[0] data[2] data[1] data[2] data[3] 8.0 14.0 2.0 3.0 5.1 4.2 6.6 0.8 3.3 3.2 5.5 6.6 2.4 6.4 0.4 4.3 12.3 3.7 9.3 3.0 data No. of rows= data.length No of columns= data[0].length A 2-D array is: a reference to a 1-D array of references to 1-D arrays of data. This is how we’ll store the matrix data in class Matrix data[0][0]
Background image of page 2
Matrix class, p.1 public class Matrix { private double[][] data; // Reference to array public Matrix(int m, int n) { data = new double[m][n]; } public void setIdentity() { int i,j; int nrows = data.length; int ncols = data[0].length; for(i=0; i<nrows; i++) for(j=0; j<ncols; j++) if(i == j) data[i][j]= 1.0; else data[i][j]= 0.0; // Not really needed }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/29/2011 for the course CIVIL 1.00 taught by Professor Georgekocur during the Spring '05 term at MIT.

Page1 / 10

lecture_22_s2005 - 1.00 Lecture 22 Matrices Reading for...

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

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