Gaussian elimination. System of Linear Equations. Gaussian elimination. System of Linear Equations

Similar documents
LU Decomposition Method Jamie Trahan, Autar Kaw, Kevin Martin University of South Florida United States of America

An Application of the Dulmage-Mendelsohn Decomposition to Sparse Null Space Bases of Full Row Rank Matrices

Parallel Numerics. 1 Preconditioning & Iterative Solvers (From 2016)

Dijkstra s Single Source Algorithm. All-Pairs Shortest Paths. Dynamic Programming Solution. Performance. Decision Sequence.

Computer Vision. Exercise Session 1. Institute of Visual Computing

Outline. Third Programming Project Two-Dimensional Arrays. Files You Can Download. Exercise 8 Linear Regression. General Regression

Problem Set 3 Solutions

KFUPM. SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture (Term 101) Section 04. Read

Dijkstra s Single Source Algorithm. All-Pairs Shortest Paths. Dynamic Programming Solution. Performance

ON SOME ENTERTAINING APPLICATIONS OF THE CONCEPT OF SET IN COMPUTER SCIENCE COURSE

Solving two-person zero-sum game by Matlab

Exercises (Part 4) Introduction to R UCLA/CCPR. John Fox, February 2005

Kent State University CS 4/ Design and Analysis of Algorithms. Dept. of Math & Computer Science LECT-16. Dynamic Programming

Programming in Fortran 90 : 2017/2018

SENSITIVITY ANALYSIS IN LINEAR PROGRAMMING USING A CALCULATOR

Lecture 4: Principal components

On Some Entertaining Applications of the Concept of Set in Computer Science Course

Sorting Review. Sorting. Comparison Sorting. CSE 680 Prof. Roger Crawfis. Assumptions

CS240: Programming in C. Lecture 12: Polymorphic Sorting

Sum of Linear and Fractional Multiobjective Programming Problem under Fuzzy Rules Constraints

Radial Basis Functions

Searching & Sorting. Definitions of Search and Sort. Linear Search in C++ Linear Search. Week 11. index to the item, or -1 if not found.

Intra-Parametric Analysis of a Fuzzy MOLP

Loop Permutation. Loop Transformations for Parallelism & Locality. Legality of Loop Interchange. Loop Interchange (cont)

Network Coding as a Dynamical System

Classification / Regression Support Vector Machines


Loop Transformations, Dependences, and Parallelization

An Application of Network Simplex Method for Minimum Cost Flow Problems

A New Approach For the Ranking of Fuzzy Sets With Different Heights

CSCI 104 Sorting Algorithms. Mark Redekopp David Kempe

Reading. 14. Subdivision curves. Recommended:

AMath 483/583 Lecture 21 May 13, Notes: Notes: Jacobi iteration. Notes: Jacobi with OpenMP coarse grain

Polyhedral Compilation Foundations

Assignment # 2. Farrukh Jabeen Algorithms 510 Assignment #2 Due Date: June 15, 2009.

Range images. Range image registration. Examples of sampling patterns. Range images and range surfaces

Face Recognition University at Buffalo CSE666 Lecture Slides Resources:

Determining the Optimal Bandwidth Based on Multi-criterion Fusion

Loop Transformations for Parallelism & Locality. Review. Scalar Expansion. Scalar Expansion: Motivation

Analysis of Continuous Beams in General

Outline. Midterm Review. Declaring Variables. Main Variable Data Types. Symbolic Constants. Arithmetic Operators. Midterm Review March 24, 2014

THE FUZZY GROUP METHOD OF DATA HANDLING WITH FUZZY INPUTS. Yuriy Zaychenko

Cluster Analysis of Electrical Behavior

Inverse Kinematics (part 2) CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Spring 2016

Using Radial Basis Functions to Solve Geodesics Equations for Body Measurements *

Content Based Image Retrieval Using 2-D Discrete Wavelet with Texture Feature with Different Classifiers

Parallel Solutions of Indexed Recurrence Equations

Introduction to Programming. Lecture 13: Container data structures. Container data structures. Topics for this lecture. A basic issue with containers

NAG Fortran Library Chapter Introduction. G10 Smoothing in Statistics

arxiv: v3 [cs.na] 18 Mar 2015

Proposed Simplex Method For Fuzzy Linear Programming With Fuzziness at the Right Hand Side

Hermite Splines in Lie Groups as Products of Geodesics

U.C. Berkeley CS294: Beyond Worst-Case Analysis Handout 5 Luca Trevisan September 7, 2017

Solitary and Traveling Wave Solutions to a Model. of Long Range Diffusion Involving Flux with. Stability Analysis

Subspace clustering. Clustering. Fundamental to all clustering techniques is the choice of distance measure between data points;

Proper Choice of Data Used for the Estimation of Datum Transformation Parameters

Sorting. Sorting. Why Sort? Consistent Ordering

2x x l. Module 3: Element Properties Lecture 4: Lagrange and Serendipity Elements

Sequential search. Building Java Programs Chapter 13. Sequential search. Sequential search

Structure from Motion

AC : TEACHING SPREADSHEET-BASED NUMERICAL ANAL- YSIS WITH VISUAL BASIC FOR APPLICATIONS AND VIRTUAL IN- STRUMENTS

CS221: Algorithms and Data Structures. Priority Queues and Heaps. Alan J. Hu (Borrowing slides from Steve Wolfman)

A One-Sided Jacobi Algorithm for the Symmetric Eigenvalue Problem

Modeling and Solving Nontraditional Optimization Problems Session 2a: Conic Constraints

Multi-stable Perception. Necker Cube

BFF1303: ELECTRICAL / ELECTRONICS ENGINEERING. Direct Current Circuits : Methods of Analysis

Insertion Sort. Divide and Conquer Sorting. Divide and Conquer. Mergesort. Mergesort Example. Auxiliary Array

Line Clipping by Convex and Nonconvex Polyhedra in E 3

A Simple and Efficient Goal Programming Model for Computing of Fuzzy Linear Regression Parameters with Considering Outliers

Today s Outline. Sorting: The Big Picture. Why Sort? Selection Sort: Idea. Insertion Sort: Idea. Sorting Chapter 7 in Weiss.

Complex Deformable Objects in Virtual Reality

CSE 326: Data Structures Quicksort Comparison Sorting Bound

More on Sorting: Quick Sort and Heap Sort

An Optimal Algorithm for Prufer Codes *

CSE 326: Data Structures Quicksort Comparison Sorting Bound

Outline. CIS 110: Introduction to Computer Programming. Review: Interactive Sum. More Cumulative Algorithms. Interactive Sum Trace (2)

A Variable Elimination Approach for Optimal Scheduling with Linear Preferences

The Methods of Maximum Flow and Minimum Cost Flow Finding in Fuzzy Network

Very simple computational domains can be discretized using boundary-fitted structured meshes (also called grids)

CS 534: Computer Vision Model Fitting

INTRODUCTION INTRODUCTION. Moisès Graells Semi-continuous processes

An Accurate Evaluation of Integrals in Convex and Non convex Polygonal Domain by Twelve Node Quadrilateral Finite Element Method

Kinematics of pantograph masts

CONCURRENT OPTIMIZATION OF MULTI RESPONCE QUALITY CHARACTERISTICS BASED ON TAGUCHI METHOD. Ümit Terzi*, Kasım Baynal

Vectorization in the Polyhedral Model

Solving Route Planning Using Euler Path Transform

Biostatistics 615/815

Priority queues and heaps Professors Clark F. Olson and Carol Zander

High resolution 3D Tau-p transform by matching pursuit Weiping Cao* and Warren S. Ross, Shearwater GeoServices

S1 Note. Basis functions.

COMPLETE CALCULATION OF DISCONNECTION PROBABILITY IN PLANAR GRAPHS. G. Tsitsiashvili. IAM, FEB RAS, Vladivostok, Russia s:

AIMS Computer vision. AIMS Computer Vision. Outline. Outline.

Positive Semi-definite Programming Localization in Wireless Sensor Networks

Programming Assignment Six. Semester Calendar. 1D Excel Worksheet Arrays. Review VBA Arrays from Excel. Programming Assignment Six May 2, 2017

Kinematics Modeling and Analysis of MOTOMAN-HP20 Robot

Support Vector Machines

Conditional Speculative Decimal Addition*

An inverse problem solution for post-processing of PIV data

Parallel Minimum Norm Solution of Sparse Block Diagonal Column Overlapped Underdetermined Systems

Compiler Design. Spring Register Allocation. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Transcription:

Jord Cortadella Department of Computer Scence Introducton to Programmng Dept. CS, UPC 2 An essental algorthm n Lnear Algebra wth multple applcatons: Solvng lnear systems of equatons Fndng the nverse of a matrx Computng determnants Computng ranks and bases of vector spaces Named after Carl Fredrch Gauss (1777-1855), but known much before by the Chnese. Alan Turng contrbuted to provde modern numercal algorthms for computers (characterzaton of ll-condtoned systems). Introducton to Programmng Dept. CS, UPC 3 Introducton to Programmng Dept. CS, UPC 4

// Type defntons for real vectors and matrces usng rvector vector<double>; usng rmatrx vector<rvector>; // Pre: A s an n n matrx, b s an n-element vector. // Returns x such that Axb. In case A s sngular, // t returns a zero-szed vector. // Post: A and b are modfed. rvector SystemEquatons(rmatrx& A, rvector& b) { bool nvertble GaussElmnaton(A, b); f (not nvertble) return rvector(); // A s n row echelon form return BackSubsttuton(A, b); Axb A x b Assumpton: trangular system of equatons wthout zeroes n the dagonal Introducton to Programmng Dept. CS, UPC 5 Introducton to Programmng Dept. CS, UPC 6 Introducton to Programmng Dept. CS, UPC 7 Introducton to Programmng Dept. CS, UPC 8

// Pre: A s an nvertble n n matrx n row echelon form, // b s a n-element vector // Returns x such that Axb rvector BackSubsttuton(const rmatrx& A, const rvector& b) { nt n A.sze(); rvector x(n); // Creates the vector for the soluton // Calculates x from x[] to x[] for (nt n - 1; > ; --) { // The values x[+1..] have already been calculated double s ; for (nt j + 1; j < n; ++j) s s + A[][j] x[j]; x[] (b[] s)/a[][]; return x; k A b Invarant: The rows..k have been reduced (zeroes at the left of the dagonal) Introducton to Programmng Dept. CS, UPC 9 Introducton to Programmng Dept. CS, UPC 1 j k What s the best pvot? (max absolute value) swap rows For each row, add a multple of row k such that A[][k] becomes zero. The coeffcent s A[][k]/A[k][k]. Introducton to Programmng Dept. CS, UPC 11 Introducton to Programmng Dept. CS, UPC 12

// Pre: A s an n n matrx, b s a n-element vector. // Returns true f A s nvertble, and false f A s sngular. // Post: If A s nvertble, A and b are the result of // the (A s n row echelon form). bool GaussanElmnaton(rmatrx& A, rvector& b) { nt n A.sze(); Dscusson: how large should a pvot be? // Reduce rows 1.. (use the pvot n prevous row k) for (nt k ; k < n - 1; ++k) { // Rows..k have already been reduced nt max fnd_max_pvot(a, k); // fnds the max pvot f (abs(a[max][k]) < 1e-1) return false; // Sngular matrx // Pre: A s an n n matrx, k s the ndex of a row. // Returns the ndex of the row wth max absolute value // for the subcolumn A[k..][k]. nt fnd_max_pvot(const rmatrx& A, nt k) { nt n A.sze(); double max k; // ndex of the row wth max pvot double max_pvot abs(a[k][k]); swap(a[k], A[max]); swap(b[k], b[max]); // Swap rows k and max // Force s n column A[k+1..][k] for (nt k + 1; < n; ++) { double c A[][k]/A[k][k]; // coeffcent to scale row A[][k] ; for (nt j k + 1; j < n; ++j) A[][j] A[][j] c A[k][j]; b[] b[] c b[k]; return true; // We have an nvertble matrx for (nt k + 1; < n; ++) { double a abs(a[][k]); f (a > max_pvot) { max_pvot a; max ; return max; Introducton to Programmng Dept. CS, UPC 13 Solvng multple systems of equatons Introducton to Programmng Dept. CS, UPC 14 // Pre: A s an nvertble n n matrx n row echelon form, // B s a n m matrx // Returns X such that AXB rmatrx BackSubsttuton(const rmatrx& A, const rmatrx& B) { nt n A.sze(); nt m B[].sze(); rmatrx X(n, rvector(m)); // Creates the soluton matrx // Calculates X from X[] to X[] for (nt n - 1; > ; --) { // The values X[+1..] have already been calculated for (nt k ; k < m; ++k) { double s ; for (nt j + 1; j < n; ++j) s s + A[][j] X[j][k]; X[][k] (B[][k] s)/a[][]; return X; Introducton to Programmng Dept. CS, UPC 15 Introducton to Programmng Dept. CS, UPC 16

Inverse of a Matrx // Pre: A s an n n matrx, B s an n m matrx. // Returns true f A s nvertble, and false f A s sngular. // Post: If A s nvertble, A and B are the result of // the (A s n row echelon form). bool GaussanElmnaton(rmatrx& A, rmatrx& B) { nt n A.sze(); nt m B[].sze(); Reduce the problem to a set of systems of lnear equatons: // Reduce rows 1.. (use the pvot n prevous row k) for (nt k ; k < n - 1; ++k) { // Rows..k have already been reduced nt max fnd_max_pvot(a, k); // fnds the max pvot f (abs(a[max][k]) < 1e-1) return false; // Sngular matrx swap(a[k], A[max]); swap(b[k], B[max]); // Swap rows k and max // Force s n column A[k+1..][k] for (nt k + 1; < n; ++) { double c A[][k]/A[k][k]; // coeffcent to scale row A[][k] ; for (nt j k + 1; j < n; ++j) A[][j] A[][j] c A[k][j]; for (nt l ; l < m; ++l) B[][l] B[][l] c B[k][l]; return true; // We have an nvertble matrx Introducton to Programmng Dept. CS, UPC 17 Computng determnants Rules of determnants: 1. Swappng two rows: determnant multpled by -1 2. Multplyng a row by a scalar: the determnant s multpled by the same scalar 3. Addng to one row the scalar multple of another row: determnant does not change Algorthm: Do and remember the number of row swaps (odd or even). The determnant s the product of the elements n the dagonal (negated n case of an odd number of swaps). Rule 2 s not used, unless some row s scaled. Introducton to Programmng Dept. CS, UPC 18 Summary s the most used algorthm n Lnear Algebra. Complexty: O(n 3 ). There are many good packages to solve Lnear Algebra operatons (LAPACK, LINPACK, Matlab, Mathematca, NumPy, R, ). Introducton to Programmng Dept. CS, UPC 19 Introducton to Programmng Dept. CS, UPC 2