Factor A in LU = O(n^3)
Gaussian Elimination = O(n^3)
Back substitution = O(n^2)
Forward substitution = O(n^2)
Assume we have m systems of linear equations
Ax[0] = b[0]
Ax[1] = b[1]
...
Ax[m] = b[m]
Using Gaussian elimination costs O(mn^3)
Using LU factorization costs O(n^3) + mO(n^2)
If m = 1, use Gaussian elimination
If m > 1, use LU factorization
------------------------------------------------------------------------------
Iterative methods for systems of linear equations
Jacobi iteration
----------------
Calculates increasingly more accurate values for 2 variables.
Example:
3x + y = 5 and x + 3y = 7
Rewrite as x = (5-y)/3 and y = (7-x)/3
x[k+1] = (5-y[k])/3
y[k+1] = (7-x[k])/3
Start at x[0] = 0 and y[0] = 0
x[1] = (5-0)/3 ≈ 1.667
y[1] = (7-0)/3 ≈ 2.333
x[2] = .889
y[2] = 1.778
x[3] = 1.074
y[3] = 2.037
x[4] = .987
y[4] = 1.975
x[∞] = 1
y[∞] = 2
3(1) + 2 = 5
1 + 3(2) = 7
Gauss-Seidel iteration
----------------------
Similar to Jacobi iteration, but doesn't include waiting until the end of iteration
to use the values of x and y
(it instead uses the new approximations of x and
y for computation as soon as they are available), causing it to converge faster.
Example:
3x + y = 5 and x + 3y = 7
x[k+1] = (5-y[k])/3
y[k+1] = (7-x[k+1])/3, as x[k+1] is already available for use
x[0] = 0
y[0] = 0
x[1] = (5-0)/3 = 1.667
y[1] = (7-1.667)/3 = 1.778
x[2] = 1.074
y[2] = 1.975
Jacobi and Gauss-Seidel
How can we ensure convergence?
Systems of non-linear equations - we extend Newton's method for equations in 2 variables
Writing approximation in matrix form, we have:
[x[1] = [x[0] - JJ^(-1)[f[1](x[0],y[0])
y[1]] y[0]] f[2](x[0],y[0])]
[f[1](x,y) = [f[1](x[0],y[0]) + [df[1](x[0],y[0])/dx df[1](x[1],y[1])/dy
f[2](x,y)] f[2](x[0],y[0])] df[2](x[0],y[0])/dx
df[2](x[1],y[1])/dy]
The last matrix is called the Jacobian, represented by double-J
To obtain the Newton method, we approximate f[1](x,y) and f[2](x,y) by
using two terms and eliminating the error.
Then we set f[1](x,y) = 0 and f[2](x,y)
= 0 for the next iteration.
Example
-------
f[1](x,y) = x^2 - y - .2 = 0
f[2](x,y) = y^2 - x - .3 = 0
df[1](x,y)/dx = 2x
df[1](x,y)/dy = -1
df[2](x,y)/dx = -1
df[2](x,y)/dy = 2y
JJ = [2x -1
-1 2y]
JJ^(-1) = [2y 1 (1/(2x2y - 1))
1 2x]
To compute inverse, use determinant and multiply by (-1)^(ij), where i
is the row number
and j is the column number (or put side-by-side with
identity
matrix,
performing the same functions on both)
i x y f[1] f[2] JJ^(-1)
---------------------------------------------------
0 0 0 -.2 -.3 [0 1 (1/(4(0)-1))
1
0]
1 -.3 -.2 .09 .04 [.526
-1.3158
-1.3158
.7895]
2 .2947 -.113158 .000006090 .0075
We want f[1] and f[2] to approach 0 as i approaches infinity
------------------------------------------------------------------------------
Taylor approximation -> a polynomial P[N] approximates a continuous function
x such that
f(x) ≈ P[N] = sum[k=0;N] (f(x[0])/k!)(x-x[0])^k
Examples:
---------
sin(x) = x - x^3/3! + x^5/5! + ....
e^x = 1 + x + x^2/2! + x^3/3! + ....
Assume ?(x) = 2x^4 + 4x^3 + 3x^2 + 2x + 1
Straight-forward: 10 multiplications and 4 additions
This is too expensive, but we can factor f(x) using "Horner's method"
f(x) = (((2x+4)x+3)x+2)x+1
Horner's method: 4 multiplications and 4 additions
Polynomial approximation using n+1 points
* If x[0] < x < x[n], approximating f(x)
at a given point via p(x) is referred to as interpolation
* If x < x[0] or x > x[n], the approximation
is called extrapolation
Lagrange Approximation
Example
-------
Approximating sin(x) on the interval [0,π/2] with degree 3 polynomial
x sin(x)
-----------
0 0
π/6 .5
π/3 .866
π/2 1
p[3](x) = 0((x-π/6)(x-π/3)(x-π/2))/((0-π/6)(0-π/3)(0-π/2))
+ .5((x-0)(x-π/3)(x-π/2))/((π/6-0)(π/6-π/3)(π/6-π/2))
+ .866((x-0)(x-π/6)(x-π/2))/((π/3-0)(π/3-π/6)(π/3-π/2))
+ 1((x-0)(x-π/6)(x-π/3))/((π/2-0)(π/2-π/6)(π/2-π/3))
p[3](x) = 1.74(x)(x-1.047)(x-1.5708)
- 3.0164(x)(x-.5236)(x-1.5708)
- 1.1611(x)(x-.5236)(x-1.047)
sin(π/4) = .7071
p[3](π/4) = .7054
Exam
Newton Method for Polynomial Approximation
Example
-------
Build polynomials
of degrees 1, 2, and 3 to approximate f(x) = sin(x) over the
interval [0,π/2]
x[k] f[x[k]] f[x[k-1],x[k]] f[x[k-2],x[k-1]]
----------------------------------------------------------
0 sin(0) = 0
π
/6 sin(π/6) = .5 .9549
π
/3 sin(π/3) = .8699 .699 -.244
π
/2 sin(π/2) = 1 .836 -.423