Solving Linear System of Equations The Undo button for Linear - - PowerPoint PPT Presentation
Solving Linear System of Equations The Undo button for Linear - - PowerPoint PPT Presentation
Solving Linear System of Equations The Undo button for Linear Operations Matrix-vector multiplication: given the data and the operator , we can find such that = transformation What if we know
The โUndoโ button for Linear Operations
Matrix-vector multiplication: given the data ๐ and the operator ๐ฉ, we can find ๐ such that ๐ = ๐ฉ ๐ What if we know ๐ but not ๐? How can we โundoโ the transformation?
๐ ๐ ๐ฉ
transformation
๐ฉ!๐ ๐ ๐ ?
Solve ๐ฉ ๐ = ๐ for ๐
Image Blurring Example
- Image is stored as a 2D array of real numbers between 0 and 1
(0 represents a white pixel, 1 represents a black pixel)
- ๐๐๐๐ has 40 rows of pixels and 100 columns of pixels
- Flatten the 2D array as a 1D array
- ๐ contains the 1D data with dimension 4000,
- Apply blurring operation to data ๐, i.e.
๐ = ๐ฉ ๐ where ๐ฉ is the blur operator and ๐ is the blurred image
Blur operator
๐ = ๐ฉ ๐
"originalโ image (4000,) blurred image (4000,) Blur operator (4000,4000) Blur operator
๐ ๐
๐ฉ
โUndoโ Blur to recover original image
Solve ๐ฉ ๐ = ๐ for ๐ Assumptions:
- 1. we know the blur
- perator ๐ฉ
- 2. the data set ๐ does not
have any noise (โclean dataโ ๐ ๐
โUndoโ Blur to recover original image
Solve ๐ฉ ๐ = ๐ for ๐
๐ + ๐ โ 10!" (๐ โ 0,1 ) How much noise can we add and still be able to recover meaningful information from the original image? At which point this inverse transformation fails? We will talk about sensitivity of the โundoโ operation later. ๐ + ๐ โ 10!# (๐ โ 0,1 )
Linear System of Equations
We can start with an โeasierโ system of equationsโฆ How do we actually solve ๐ฉ ๐ = ๐ ? Letโs consider triangular matrices (lower and upper):
๐!! ๐"! ๐"" โฆ โฆ โฎ โฎ ๐#! ๐#" โฑ โฎ โฆ ๐## ๐ฆ! ๐ฆ" โฎ ๐ฆ# = ๐ ๐" โฎ ๐# ๐!! ๐!" ๐"" โฆ ๐!# โฆ ๐"# โฎ โฎ โฑ โฎ โฆ ๐## ๐ฆ! ๐ฆ" โฎ ๐ฆ# = ๐ ๐" โฎ ๐#
2 3 2 1 2 1 3 6 4 2 ๐ฆ! ๐ฆ" ๐ฆ# ๐ฆ$ = 2 2 6 4
Example: Forward-substitution for lower triangular systems
2 ๐ฆ$ = 2 โ ๐ฆ$= 1 3 ๐ฆ$ + 2 ๐ฆ% = 2 โ ๐ฆ%= 2 โ 3 2 = โ0.5 1 ๐ฆ$ + 2 ๐ฆ% + 6 ๐ฆ& = 6 โ ๐ฆ&= 6 โ 1 + 1 6 = 1.0 1 ๐ฆ$ + 3 ๐ฆ% + 4 ๐ฆ& + 2 ๐ฆ# = 4 โ ๐ฆ&= 4 โ 1 + 1.5 โ 4 2 = 0.25
๐ฆ! ๐ฆ" ๐ฆ# ๐ฆ$ = 1 โ0.5 1.0 0.25
Triangular Matrices
๐!! ๐!" ๐"" โฆ ๐!# โฆ ๐"# โฎ โฎ โฑ โฎ โฆ ๐## ๐ฆ! ๐ฆ" โฎ ๐ฆ# = ๐ ๐" โฎ ๐#
๐ฆ! ๐ : , 1 + ๐ฆ" ๐ : , 2 + โฏ + ๐ฆ% ๐ : , ๐ = ๐ Hence we can write the solution as
๐'' ๐ฆ' = ๐'
Recall that we can also write ๐ฝ ๐ = ๐ as a linear combination of the columns of ๐ฝ
๐ฆ$ ๐ : , 1 + โฏ + ๐ฆ'!$ ๐ : , ๐ โ 1 = ๐ โ๐ฆ' ๐ : , ๐ โ ๐'!$,'!$ ๐ฆ'!$ = ๐'!$ โ ๐'!$,' ๐ฆ' ๐ฆ$ ๐ : , 1 + โฏ + ๐ฆ'!% ๐ : , ๐ โ 2 = ๐ โ๐ฆ' ๐ : , ๐ โ ๐ฆ'!$ ๐ : , ๐ โ 1
Or in general (backward-substitution for upper triangular systems): ๐ฆ&= ๐& โ โ'(&)!
%
๐&'๐ฆ' ๐&& , ๐ = ๐ โ 1, ๐ โ 2, โฆ , 1 ๐ฆ% = ๐%/๐%%
Forward-substitution for lower-triangular systems: ๐ฆ&= ๐& โ โ'(!
&*! ๐&'๐ฆ'
๐&& , ๐ = 2,3, โฆ , ๐ ๐ฆ! = ๐!/๐!!
๐!! ๐"! ๐"" โฆ โฆ โฎ โฎ ๐#! ๐#" โฑ โฎ โฆ ๐## ๐ฆ! ๐ฆ" โฎ ๐ฆ# = ๐ ๐" โฎ ๐#
Triangular Matrices
Cost of solving triangular systems
๐ฆ&= ๐& โ โ'(&)!
%
๐&'๐ฆ' ๐&& , ๐ = ๐ โ 1, ๐ โ 2, โฆ , 1 ๐ฆ% = ๐%/๐%%
๐ divisions ๐ ๐ โ 1 /2 subtractions/additions ๐ ๐ โ 1 /2 multiplications
Computational complexity is ๐(๐")
๐ divisions ๐ ๐ โ 1 /2 subtractions/additions ๐ ๐ โ 1 /2 multiplications
Computational complexity is ๐(๐")
๐ฆ&= ๐& โ โ'(!
&*! ๐&'๐ฆ'
๐&& , ๐ = 2,3, โฆ , ๐ ๐ฆ! = ๐!/๐!!
Linear System of Equations
How do we solve ๐ฉ ๐ = ๐ when ๐ฉ is a non-triangular matrix? We can perform LU factorization: given a ๐ร๐ matrix ๐ฉ,
- btain lower triangular matrix ๐ด and upper triangular matrix
๐ฝ such that where we set the diagonal entries of ๐ด to be equal to 1.
๐ฉ = ๐ด๐ฝ
1 ๐"! 1 โฆ โฆ โฎ โฎ ๐#! ๐#" โฑ โฎ โฆ 1 ๐!! ๐!" ๐"" โฆ ๐!# โฆ ๐"# โฎ โฎ โฑ โฎ โฆ ๐## = ๐ต!! ๐ต!" ๐ต"! ๐ต"" โฆ ๐ต!# โฆ ๐ต"# โฎ โฎ ๐ต#! ๐ต#" โฑ โฎ โฆ ๐ต##
LU Factorization
1 ๐"! 1 โฆ โฆ โฎ โฎ ๐#! ๐#" โฑ โฎ โฆ 1 ๐!! ๐!" ๐"" โฆ ๐!# โฆ ๐"# โฎ โฎ โฑ โฎ โฆ ๐## = ๐ต!! ๐ต!" ๐ต"! ๐ต"" โฆ ๐ต!# โฆ ๐ต"# โฎ โฎ ๐ต#! ๐ต#" โฑ โฎ โฆ ๐ต##
๐ด๐ฝ ๐ = ๐ ๐ด ๐ = ๐
Forward-substitution with complexity ๐(๐")
๐ฝ ๐ = ๐
Solve for ๐ Backward-substitution with complexity ๐(๐") Solve for ๐ Assuming the LU factorization is know, we can solve the general system By solving two triangular systems: But what is the cost of the LU factorization? Is it beneficial?
2x2 LU Factorization (simple example)
๐ต!! ๐ต!" ๐ต"! ๐ต"" = 1 ๐"! 1 ๐!! ๐!" ๐""
๐ต!! ๐ต!" ๐ต"! ๐ต"" = ๐!! ๐!" ๐"!๐!! ๐"!๐!" + ๐""
2) ๐=> = ๐ต=>/๐>> 3) ๐== = ๐ต== โ ๐=>๐>= Seems quite simple! Can we generalize this for a ๐ร๐ matrix ๐ฉ? ๐>> = ๐ต=>/๐>>
LU Factorization
๐ต!! ๐ต!" ๐ต"! ๐ต"" โฆ ๐ต!# โฆ ๐ต"# โฎ โฎ ๐ต#! ๐ต#" โฑ โฎ โฆ ๐ต## = ๐!! ๐!" ๐"! ๐ฉ"" = 1 ๐ ๐"! ๐ด"" ๐ฃ!! ๐!" ๐ ๐ฝ""
๐$$ ๐$% ๐%$ ๐ฉ%% ๐$$: scalar ๐$%: row vector (1ร(๐ โ 1)) ๐%$: column vector (๐ โ 1)ร1 ๐ฉ%%: matrix (๐ โ 1)ร(๐ โ 1)
๐!! ๐!" ๐"! ๐ฉ"" = ๐ฃ!! ๐!" ๐ฃ!! ๐"! ๐"!๐!" + ๐ด""๐ฝ""
1) First row of ๐ฝ is the first row of ๐ฉ ๐=> = >
+!! ๐=>
3) ๐ด""๐ฝ"" = ๐ฉ"" โ ๐"!๐!" Need another factorization!
Known!
2) First column of ๐ด is the first column of ๐ฉ/ ๐ฃ>>
๐ฉ"" = ๐"!๐!" + ๐ด""๐ฝ""
LU Factorization
๐ต!! ๐ต!" ๐ต"! ๐ต"" โฆ ๐ต!# โฆ ๐ต"# โฎ โฎ ๐ต#! ๐ต#" โฑ โฎ โฆ ๐ต## = ๐!! ๐!" ๐"! ๐ฉ"" = 1 ๐ ๐"! ๐ด"" ๐ฃ!! ๐!" ๐ ๐ฝ""
๐$$ ๐$% ๐%$ ๐ฉ%% ๐$$: scalar ๐$%: row vector (1ร(๐ โ 1)) ๐%$: column vector (๐ โ 1)ร1 ๐ฉ%%: matrix (๐ โ 1)ร(๐ โ 1)
๐!! ๐!" ๐"! ๐ฉ"" = ๐ฃ!! ๐!" ๐ฃ!! ๐"! ๐"!๐!" + ๐ด""๐ฝ""
1) First row of ๐ฝ is the first row of ๐ฉ 2) ๐=> = >
+!! ๐=>
3) ๐ต = ๐ด""๐ฝ"" = ๐ฉ"" โ ๐"!๐!" Need another factorization!
Known!
First column of ๐ด is the first column of ๐ฉ/ ๐ฃ>>
Example
๐ต = 2 8 1 2 4 1 3 3 1 2 1 3 6 2 4 2
1) First row of ๐ฝ is the first row of ๐ฉ 2) First column of ๐ด is the first column of ๐ฉ/ ๐ฃ>>
3) ๐ด""๐ฝ"" = ๐ฉ"" โ ๐"!๐!"
Example
๐ต = 2 8 1 2 4 1 3 3 1 2 1 3 6 2 4 2 ๐ฝ = 2 8 4 1 ๐ด = 1 0.5 0.5 0.5 ๐ต = 2 8 1 โ2 4 1 1 2.5 1 โ2 1 โ1 4 1.5 2 1.5 ๐ฝ = 2 8 โ2 4 1 1 2.5 ๐ด = 1 0.5 1 0.5 1 0.5 0.5 ๐ต = 2 8 1 โ2 4 1 1 2.5 1 โ2 1 โ1 3 โ1 1.5 0.25 ๐ฝ = 2 8 โ2 4 1 1 2.5 3 โ1 ๐ด = 1 0.5 1 0.5 1 0.5 0.5 1 0.5 ๐ฝ = 2 8 โ2 4 1 1 2.5 3 โ1 0.75 ๐ด = 1 0.5 1 0.5 1 0.5 0.5 1 0.5 1 ๐ต = 2 8 1 โ2 4 1 1 2.5 1 โ2 1 โ1 3 โ1 1.5 0.75
Algorithm: LU Factorization of matrix A
Cost of LU factorization
$
"#$ %
๐ = 1 2 ๐ ๐ + 1 $
"#$ %
๐& = 1 6 ๐ ๐ + 1 2๐ + 1
Side note:
Cost of LU factorization
Number of divisions: ๐ โ 1 + ๐ โ 2 + โฏ + 1 = ๐ ๐ โ 1 /2 Number of multiplications ๐ โ 1 % + ๐ โ 2 % + โฆ + 1 % =
'! & โ '" % + ' "
Number of subtractions: ๐ โ 1 % + ๐ โ 2 % + โฆ + 1 % =
'! & โ '" % + ' "
Computational complexity is ๐(๐,)
$
"#$ %
๐ = 1 2 ๐ ๐ + 1 $
"#$ %
๐& = 1 6 ๐ ๐ + 1 2๐ + 1
Side note: Demo โComplexity of Mat-Mat multiplication and LUโ
Solving linear systems
In general, we can solve a linear system of equations following the steps: 1) Factorize the matrix ๐ฉ : ๐ฉ = ๐ด๐ฝ (complexity ๐(๐C))
2) Solve ๐ด ๐ = ๐ (complexity ๐(๐=))
3) Solve ๐ฝ ๐ = ๐ (complexity ๐(๐=))
But why should we decouple the factorization from the actual solve? (Remember from Linear Algebra, Gaussian Elimination does not decouple these two stepsโฆ)
Example: Optimization of automotive control arm
Find the distribution of material inside the design space (๐) that maximizes the stiffness, i.e., min ๐ฝ,๐ฎ where ๐ณ ๐ ๐ฝ = ๐ฎ (๐ฝ: displacement vector, ๐ฎ: load vector, ๐ณ: stiffness matrix) Solve the linear system of equations ๐ณ ๐ฝ = ๐ฎ for the load vector ๐ฎ. What if we have many different loading conditions (pothole, hitting a curb, breaking, etc)?
Iclicker question
Letโs assume that when solving the system of equations ๐ณ ๐ฝ = ๐ฎ, we observe the following:
- When the stiffness matrix has dimensions (100,100), computing the LU factorization
takes about 1 second and each solve (forward + backward substitution) takes about 0.01 seconds. Estimate the total time it will take to find the displacement response corresponding to 10 different load vectors ๐ฎ when the stiffness matrix has dimensions (1000,1000)? ๐ต) ~10 ๐ก๐๐๐๐๐๐ก ๐ถ) ~10" ๐ก๐๐๐๐๐๐ก ๐ท) ~10# ๐ก๐๐๐๐๐๐ก ๐ธ) ~10$ ๐ก๐๐๐๐๐๐ก ๐น) ~10- ๐ก๐๐๐๐๐๐ก
What can go wrong with the previous algorithm?
If division by zero occurs, LU factorization fails. What can we do to get something like an LU factorization?
What can go wrong with the previous algorithm?
๐ต = 2 8 1 ๐ 4 1 3 3 1 2 1 3 6 2 4 2 ๐ฝ = 2 8 4 1 ๐ด = 1 0.5 0.5 0.5 ๐ต โ ๐"!๐!" = 2 8 1 ๐ 4 1 1 2.5 1 โ2 1 โ1 4 1.5 2 1.5 ๐"!๐!" = 4 2 0.5 4 2 0.5 4 2 0.5
The next update for the lower triangular matrix will result in a division by zero! LU factorization fails. What can we do to get something like an LU factorization?
Demo โLittle cโ
Pivoting
Approach:
- 1. Swap rows if there is a zero entry in the diagonal
- 2. Even better idea: Find the largest entry (by absolute value) and
swap it to the top row. The entry we divide by is called the pivot. Swapping rows to get a bigger pivot is called (partial) pivoting.
๐!! ๐!" ๐"! ๐ฉ"" = ๐ฃ!! ๐!" ๐ฃ!! ๐"! ๐"!๐!" + ๐ด""๐ฝ"" Find the largest entry (in magnitude)
LU Factorization with Partial Pivoting
- LU factorization with partial pivoting can be completed for any matrix A
Suppose you are at stage k and there is no non-zero entry on or below the diagonal in column k. At this point, there is nothing else you can do, so the algorithm leaves a zero in the diagonal entry of U. Note that the matrix U is singular, and so is the matrix A. Subsequent backward substitutions using U will fail, but the LU factorization itself is still completed.
LU Factorization with Partial Pivoting
where ๐ธ is a permutation matrix Then solve two triangular systems:
๐ฉ = ๐ธ๐ด๐ฝ ๐ด ๐ = ๐ธ#๐ ๐ฝ ๐ = ๐
(Solve for ๐) (Solve for ๐)
๐ฉ ๐ = ๐ โ ๐ธ๐ด๐ฝ ๐ = ๐ โ ๐ด๐ฝ ๐ = ๐ธ#๐
Example
๐ฉ = ๐ต = 2 8 1 2 4 1 3 3 1 2 1 3 3 2 4 2 ๐ฝ = 2 8 4 1 ๐ด = 1 0.5 0.5 0.5 ๐ต = 2 8 1 โ2 4 1 1 2.5 1 โ2 1 โ1 1 1.5 2 1.5 ๐ฝ = 2 8 โ2 4 1 1 2.5 ๐ด = 1 0.5 1 0.5 1 0.5 0.5 ๐ต = 2 8 1 โ2 4 1 1 2.5 1 โ2 1 โ1 โ1 1.5 0.25 ๐ต = 2 8 1 โ2 4 1 1 2.5 1 โ1 1 โ2 1.5 0.25 โ1 ๐ฝ = 2 8 โ2 4 1 1 2.5 1.5 0.25 โ1 ๐ฝ = 2 8 โ2 4 1 1 2.5 ๐ด = 1 0.5 1 0.5 0.5 0.5 1.0 ๐ด = 1 0.5 1 0.5 0.5 0.5 1.0 1.0 1.0
Demo โPivoting exampleโ
๐ฉ = 2 1 4 3 1 3 1 8 7 6 7 9 5 9 8 ๐ฝ = 8 7 9 5 ๐ด = 1 0.5 0.25 0.75 Y ๐ฉ = ๐ธ๐ฉ = 1 1 1 1 2 1 4 3 1 3 1 8 7 6 7 9 5 9 8 = 8 7 4 3 9 5 3 1 2 1 6 7 1 9 8
D ๐ฉ โ ๐%$๐$% = 8 7 4 โ0.5 9 5 โ1.5 โ1.5 2 โ0.75 6 1.75 โ1.25 โ1.25 2.25 4.25 ๐%$๐$% = 3.5 4.5 2.5 1.75 2.25 1.25 5.25 6.75 3.75
Demo โPivoting exampleโ
๐ฝ = 8 7 1.75 9 5 2.25 4.25 ๐ด = 1 0.75 1 0.25 โ0.428 0.5 โ0.285 7 ๐ฉ = ๐ธ7 ๐ฉ = 1 1 1 1 8 7 6 1.75 9 5 2.25 4.25 2 โ0.75 4 โ0.5 โ1.25 โ1.25 โ1.5 โ1.5 = 8 7 6 1.75 9 5 2.25 4.25 2 โ0.75 4 โ0.5 โ1.25 โ1.25 โ1.5 โ1.5 7 ๐ฉ = 7 ๐ฉ โ ๐&$๐$& = 8 7 4 โ0.5 9 5 โ1.5 โ1.5 2 โ0.75 6 1.75 โ1.25 โ1.25 2.25 4.25 ๐&$๐$& = โ0.963 โ1.819 โ0.6412 โ1.2112 7 ๐ฉ = 7 ๐ฉ โ ๐&$๐$& = 8 7 6 1.75 9 5 2.25 4.25 2 โ0.75 4 โ0.5 โ0.287 0.569 โ0.8587 โ0.2887
Demo โPivoting exampleโ
๐ฝ = 8 7 1.75 9 5 2.25 4.25 โ0.86 โ0.29 ๐ด = 1 0.75 1 0.5 โ0.285 0.25 โ0.428 1 0.334 7 ๐ฉ = ๐ธ7 ๐ฉ = 1 1 1 1 8 7 6 1.75 9 5 2.25 4.25 2 โ0.75 4 โ0.5 โ0.287 0.569 โ0.8587 โ0.2887 = 8 7 6 1.75 9 5 2.25 4.25 4 โ0.5 2 โ0.75 โ0.8587 โ0.2887 โ0.287 0.569 7 ๐ฉ = 7 ๐ฉ โ ๐&$๐$& = 8 7 6 1.75 9 5 2.25 4.25 2 โ0.75 4 โ0.5 โ0.287 0.569 โ0.8587 โ0.2887 ๐ฝ = 8 7 1.75 9 5 2.25 4.25 โ0.86 โ0.29 0.67 ๐ด = 1 0.75 1 0.5 โ0.285 0.25 โ0.428 1 0.334 1
๐ธ = 1 1 1 1