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



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

Beginner s Matlab Tutorial

6. Cholesky factorization

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial VI

MatLab - Systems of Differential Equations

2+2 Just type and press enter and the answer comes up ans = 4

Solving Systems of Linear Equations Using Matrices

General Framework for an Iterative Solution of Ax b. Jacobi s Method

Programming Exercise 3: Multi-class Classification and Neural Networks

Polynomial Neural Network Discovery Client User Guide

7. LU factorization. factor-solve method. LU factorization. solving Ax = b with A nonsingular. the inverse of a nonsingular matrix

14:440:127 Introduction to Computers for Engineers. Notes for Lecture 06

COS702; Assignment 6. Point Cloud Data Surface Interpolation University of Southern Missisippi Tyler Reese December 3, 2012

The Matrix Stiffness Method for 2D Trusses

Manifold Learning Examples PCA, LLE and ISOMAP

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Solving Systems of Linear Equations

Algebra Unpacked Content For the new Common Core standards that will be effective in all North Carolina schools in the school year.

Using MATLAB to Measure the Diameter of an Object within an Image

CS3220 Lecture Notes: QR factorization and orthogonal transformations

(!' ) "' # "*# "!(!' +,

Lecture 3: Finding integer solutions to systems of linear equations

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

x y The matrix form, the vector form, and the augmented matrix form, respectively, for the system of equations are

Reduced echelon form: Add the following conditions to conditions 1, 2, and 3 above:

1 Finite difference example: 1D implicit heat equation

The Image Deblurring Problem

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

1 Topic. 2 Scilab. 2.1 What is Scilab?

MATLAB and Big Data: Illustrative Example

Lecture 5: Singular Value Decomposition SVD (1)

CS 5614: (Big) Data Management Systems. B. Aditya Prakash Lecture #18: Dimensionality Reduc7on

SOLVING LINEAR SYSTEMS

GeoGebra. 10 lessons. Gerrit Stols

Operation Count; Numerical Linear Algebra

Matrix Multiplication

is in plane V. However, it may be more convenient to introduce a plane coordinate system in V.

EQUATIONS and INEQUALITIES

Introduction to Matlab

Linear Programming I

Direct Methods for Solving Linear Systems. Matrix Factorization

Getting to know your TI-83

Linear Programming. March 14, 2014

Arithmetic and Algebra of Matrices

A Direct Numerical Method for Observability Analysis

Lecture Notes 2: Matrices as Systems of Linear Equations

POISSON AND LAPLACE EQUATIONS. Charles R. O Neill. School of Mechanical and Aerospace Engineering. Oklahoma State University. Stillwater, OK 74078

@ MAXSTOR= Note that it s tempting to use the auxiliary variables representing loga, logb or logc since, as we noted last time,

Break-even analysis. On page 256 of It s the Business textbook, the authors refer to an alternative approach to drawing a break-even chart.

CHAPTER 3. INTRODUCTION TO MATRIX METHODS FOR STRUCTURAL ANALYSIS

Gerrit Stols

Section 8.2 Solving a System of Equations Using Matrices (Guassian Elimination)

Similar matrices and Jordan form

How To Understand And Solve A Linear Programming Problem

Unit 1 Equations, Inequalities, Functions


10.2 ITERATIVE METHODS FOR SOLVING LINEAR SYSTEMS. The Jacobi Method

Linear Equations ! $ & " % & " 11,750 12,750 13,750% MATHEMATICS LEARNING SERVICE Centre for Learning and Professional Development

Linear Algebra and TI 89

MATH2210 Notebook 1 Fall Semester 2016/ MATH2210 Notebook Solving Systems of Linear Equations... 3

Machine Learning and Data Mining. Regression Problem. (adapted from) Prof. Alexander Ihler

Thnkwell s Homeschool Precalculus Course Lesson Plan: 36 weeks

Solving Systems of Linear Equations

MATH APPLIED MATRIX THEORY

Solving Simultaneous Equations and Matrices

Methods for Finding Bases

Introduction to Numerical Math and Matlab Programming

Component Ordering in Independent Component Analysis Based on Data Power

Typical Linear Equation Set and Corresponding Matrices

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

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

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

Linear Algebra Notes

6 Scalar, Stochastic, Discrete Dynamic Systems

CHAPTER 11: BASIC LINEAR PROGRAMMING CONCEPTS

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

Matrix Algebra in R A Minimal Introduction

Tutorial 2: Using Excel in Data Analysis

Definition 8.1 Two inequalities are equivalent if they have the same solution set. Add or Subtract the same value on both sides of the inequality.

Abstract: We describe the beautiful LU factorization of a square matrix (or how to write Gaussian elimination in terms of matrix multiplication).

Data Mining: Algorithms and Applications Matrix Math Review

FACTORING SPARSE POLYNOMIALS

Chapter 6: Break-Even & CVP Analysis

Chapter 2. Software: (preview draft) Getting Started with Stella and Vensim

CS171 Visualization. The Visualization Alphabet: Marks and Channels. Alexander Lex [xkcd]

Financial Econometrics MFE MATLAB Introduction. Kevin Sheppard University of Oxford

MAT 200, Midterm Exam Solution. a. (5 points) Compute the determinant of the matrix A =

521493S Computer Graphics. Exercise 2 & course schedule change

Chapter 6. Orthogonality

Bayesian Machine Learning (ML): Modeling And Inference in Big Data. Zhuhua Cai Google, Rice University

Bedford, Fowler: Statics. Chapter 4: System of Forces and Moments, Examples via TK Solver

Name: Section Registered In:

Figure 1. An embedded chart on a worksheet.

Scatter Plot, Correlation, and Regression on the TI-83/84

1 Solving LPs: The Simplex Algorithm of George Dantzig

1 Determinants and the Solvability of Linear Systems

APPM4720/5720: Fast algorithms for big data. Gunnar Martinsson The University of Colorado at Boulder

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

Transcription:

WEEK #3, Lecture 1: Sparse Systems, MATLAB Graphics Visualization of Matrices Good visuals anchor any presentation. MATLAB has a wide variety of ways to display data and calculation results that can be powerful tools in presenting information. Recall our heat distribution example from last week:

2 The heat-balance equations: T 1 : 20+T 2 +T 6 3 T 1 = 0 T 2 : T 1 +20+T 3 +T 7 4 T 2 = 0 T 3 : T 2 +20+T 4 +T 8 4 T 3 = 0 T 4 : T 3 +20+T 5 +T 9 4 T 4 = 0 T 5 : T 4 +20+120+T 10 4 T 5 = 0 T 6 : T 1 +T 7 +T 11 3 T 6 = 0 T 7 :. T 6 +T 2 +T 8 +T 12 4 T 6 = 0

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 3 Matrix form 3 1 0 0 0 1 0... 1 4 1 0 0 0 1 0... 0 1 4 1 0 0 0 1 0... 0 0 1 4 1 0 0 0 1... 0 0 0 1 4 0 0 0 0... 1 0 0 0 0 3 1 0 0... 0 1 0 0 0 1 4 1 0... 0 0 1 0 0 0 1 4 1.... T 1 T 2 T 3 T 4 T 5 T 6 T 7 T 8 T 9 T 10 T 11. = 20 20 20 20 (20+120) 0 0 0 0 120 0.

4 Solving and Interpreting Exercise: Download W3 1.m, which creates and solves the plate temperature equations for a 5 5 grid. Explain what each of the final steps does. T = A \ B; Tm = reshape(t, N, N) pcolor(tm) colorbar

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 5 Explain why we only see a 4 4 grid on the screen, even though Tm is a 5 5 matrix. Explain what else is wrong with the temperature plot displayed by pcolor, relative to the temperature problem.

6 Refining the plot These commands get us close to the image we want. However, we still want to have the x and y axes scaled so that our plate has the correct dimensions, 1 cm 1 cm, and get the vertical ordering of the data correct. To accomplish this, we ll need to introduce a new command, meshgrid.

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 7 Adding coordinates with meshgrid Exercise: Use the following commands to plot the grid of temperatures. [X, Y] = meshgrid(linspace(0, 1, 5), linspace(0, 1, 5)) pcolor(x, Y, Tm) colorbar What changes in the pcolor plot?

8 How meshgrid works Here are the X and Y matrices created by meshgrid, along with the original Tm temperature matrix. X = 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 0 0.2500 0.5000 0.7500 1.0000 Y = 0 0 0 0 0 0.2500 0.2500 0.2500 0.2500 0.2500 0.5000 0.5000 0.5000 0.5000 0.5000 0.7500 0.7500 0.7500 0.7500 0.7500 1.0000 1.0000 1.0000 1.0000 1.0000 Tm = 38.1938 39.7321 43.5407 51.7942 70.7147 54.8493 57.1940 62.6366 72.9213 91.0645 69.1600 71.5580 76.8905 86.1899 100.6219 81.0729 82.9873 87.1774 94.3261 105.2330 91.0713 92.1411 94.5056 98.7040 105.9843

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 9 How does the pcolor(x, Y, Tm) command use all this information to generate the plot?

10 With the help of meshgrid, our pcolor plot is now correctly scaled along the x and y axes. Inverting the y ordering Finally, we want to make sure that the top-left corner in our matrix shows up in the top-left corner of our graph. From the meshgrid output, what is the y coordinate assigned to the first row of Y? Exercise: What vector does the command linspace(1, 0, 5) generate? Exercise: Using that new linspace command for the y points in meshgrid, what do the first row and column of Y look like?

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 11 Final Display Code [X, Y] = meshgrid(linspace(0, 1, N), linspace(1, 0, N)) pcolor(x, Y, Tm) colorbar Other plotting options: surf(x, Y, Tm) colorbar shading flat shading interp contour(x, Y, Tm, 0:10:100)

12 Speed of computation Now that we have successfully graphed a simple 5 5 grid of temperatures, we consider the problem of generating and displaying the equilibrium temperatures using a finer grid. Exercise: Start with the script W3 2.m. Modify it so it generates a 20 20 grid and run it. Note the approximate run time. Exercise: Incrementally increase N by 20 and re-run the script. When does it start getting slow enough to be annoying?

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 13 Matrix Characteristics Unfortunately, the value of N that slows MATLAB to a crawl does not result in a particularly detailed temperature grid. Since the accuracy of our calculation depends on how small each sub-cell in the plate is, we would really like to use a finer grid. Let s investigate further. Exercise: Type clear to clear MATLAB s memory. Then run the script with N = 60. Type spy(a) to see where the non-zero elements are in A. What do you notice? If there are roughly 5 entries per row in A, what fraction of its values are non-zero? How much space have we wasted storing the number 0 over and over again?

14 Common Matrix Structure Both trusses and heat distribution equation matrices are based on connectivity properties. Trusses: eachbeam(columnofvalues)appearsinatmost2joints,or4equations (horizontal and vertical force equations, for 2 joints). Heat: each row models temperature at a grid point; non-zero coefficients only for neighbouring grid points. In both cases, the number of non-zero elements in the A matrix will be very small relative to the numberof zeros. In these cases, if we stored the matrix in full, the vast majority of the values we store would be largely redundant zero values.

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 15 Sparse Matrices Matrices with relatively few non-zero elements are called sparse matrices There are two important implications of using sparse matrices in computer programs. Memory: Much less memory is needed to store sparse matrices. Instead of storing every entry in the matrix, just the non-zero elements are stored, along with their coordinates in the matrix. Run Time: Algorithms like Gaussian elimination can be coded to accept sparse matrices as input. How would knowing a matrix was sparse save time during row operations?

16 Notethatseeinglotsofzerosinamatrixmakesitconceptually sparse, butonlyby explicitly creating and storing the matrix in sparse format would it provide any practical advantage. Here is our original, conceptually sparse matrix, in standard form 3 1 0 0 0 1 0... 1 4 1 0 0 0 1 0... 0 1 4 1 0 0 0 1 0... 0 0 1 4 1 0 0 0 1... 0 0 0 1 4 0 0 0 0... 1 0 0 0 1 3 1 0 0... 0 1 0 0 0 1 4 1 0... 0 0 1 0 0 0 1 4 1.... This format requires storing n 2 numbers for an n n matrix. Almost all of these numbers are zeros.

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 17 The same matrix can also be stored in an explicit sparse format: A(1,1) = -3; A(1,2) = 1; A(1,5) = 1; A(2,1) = 1; A(2,2) = -4; A(2,3) = 1;. By implication, any element that isn t explicitly listed must be a zero. For each element, sparse storage is a little more expensive, because we store both the location and value, but if 90% of the values in A are zeros, we will still save more space overall by not having to store the zero values.

18 Empirical Comparison Exercise: Set N = 80 in W3 2.m. This makes A a 6400 6400 matrix, with roughly 40 million elements. Using regular format, solving takes seconds Exercise: Change the command A = zeros(nsq, Nsq) to A = sparse(nsq, Nsq) Using sparse format, solving takes seconds.

Week 3 Sparse Matrices, Inverses, Non-Linear Equations 19 We now try an even larger case. Using a 250 250 plate grid (62,500 10 5 temperature values, or a matrix A with 10 10 values). Exercise: What happens if we try to create this A matrix using regular format, with A = zeros(nsq, Nsq)? Exercise: If we use the sparse matrix format instead, can the 62,500 62,500 A matrix be built successfully? If so, how long does it take to solve the equations and generate the plot? In fact, using the sparse approach, most computer time in the script is spent creating the A matrix, not solving the final equations!

20 Sparse Summary If a problem leads naturally to a sparse matrix, it can be a huge advantage. Storage of sparse matrices is compact, so larger matrices can be stored. Specially designed algorithms can save orders of magnitude of time. Unfortunately, you can t choose sparseness: problem types either lead to sparse matrices, or they don t. Also, even if a system is conceptually sparse, you need to make sure that your software takes advantage of the sparse structure of the equations/matrices. e.g. in MATLAB, creating the matrix with the sparse command, rather than zeros.