Processing math: 100%

A.Kaw矩阵代数初步学习笔记 8. Gauss-Seidel Method

“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授。
PDF格式学习笔记下载(Academia.edu)
第8章课程讲义下载(PDF)

Summary

  • Algorithm
    Given a general set of n equations and n unknowns {a11x1+a12x2++a1nxn=c1a21x1+a22x2++a2nxn=c2an1x1+an2x2++annxn=cn If the diagonal elements are non-zero, each equation is rewritten for the corresponding unknown, that is, {x1=c1a12x2a13x3a1nxna11x2=c2a21x1a23x3a2nxna22xn=cnan1x1an2x2an,n1xn1a11 {x1=c1nj=1,j1a1jxja11x2=c1nj=1,j2a2jxja22xn=cnnj=1,jnanjxjann Hence for any row i, xi=cinj=1,jiaijxjaii where i=1, 2, , n.
  • Iteration
    To find xi, we assume an initial guess for the xi and then use the rewritten equations to calculate the new estimates. We always use the most recent estimates to calculate the next estimates, xi. At the end of each iteration, we calculate the absolute relative approximate error for each xi as εi=|xnewixoldixnewi| where xnewi is the recently obtained value of xi, and xoldi is the previous value of xi. When the absolute relative approximate error for each xi is less than the pre-specified tolerance, the iterations are stopped.
  • Convergent
    The coefficient matrix [A] in [A][X]=[B] must be diagonally dominant, that is, {|aii|nj=1,jiaijfor all i|aii|>nj=1,jiaijfor at least one i
  • An example
    Suppose the following system of equations {12x1+3x25x3=1x1+5x2+3x3=283x1+7x2+13x3=76 Use [x1x2x3]=[101] as the initial guess and conduct two iterations.
    • Diagonally dominant test: {|a11|=12>|a12|+|a13|=3+5=8|a22|=5>|a21|+|a23|=1+3=4|a33|=13>|a31|+|a32|=3+7=10 Hence the solution should converge using Gauss Seidel method.
    • Rewriting the equations: {x1=13x2+5x312x2=28x13x35x3=763x17x213 And the initial value is [x1x2x3]=[101]
    • Iteration 1: {x1=13×0+5×112=0.5x2=280.53×15=4.9x3=763×0.57×4.913=3.0923 Notice that the second and the third equations above, x1 and x2 are updated immediately. And the absolute relative approximate error is {ε1=|0.51|0.5=1ε2=|4.90|4.9=1ε3=|3.09231|3.0923=0.67662
    • Iteration 2: {x1=13×4.9+5×3.092312=0.14679x2=280.146793×3.09235=3.7153x3=763×0.146797×3.715313=3.8118 And the absolute relative approximate error is {ε1=|0.146790.5|0.14679=2.4ε2=|3.71534.9|3.7153=0.31889ε3=|3.81183.0923|3.8118=0.18874
    • Final result:
      After 6 iterations, we have the solution [x1x2x3]=[0.999193.00014.0001] which is very close to the exact solution [x1x2x3]=[134]
  • R code:
    Some comments:
    • In the second function PrepA, we use the elementary row operation Ri+mRj if the diagonal element in Ri equals to zero.
    • In the third function IterSolve, we use ε=|xnewxold| instead of the absolute relative approximate error.
    • x0 is a vector in the main function, which is the initial guess of the system. And eps is the tolerance of the error, which can be smaller or bigger in different cases. The last parameter is maxit is the number of iterations, it does not need to be too much in most cases.
    • Using this code to calculate the previous example:
      A = matrix(c(12, 1, 3, 3, 5, 7, -5, 3, 13), ncol = 3)
      b = matrix(c(1, 28, 76), ncol = 1)
      IterSolve(A, b, c(1, 0, 1))$x
      # Result
      # Converged after  11 iterations
      # [1] 1 3 4

Selected Problems

1. Given the system of equations {3x1+7x2+13x3=76x1+5x2+3x3=2812x1+3x25x3=1 find the solutions using the Gauss-Seidel method. Use [x1x2x3]=[101] as the initial guess.

Solution: Note that the coefficient matrix is not diagonal dominant: {|a11|=3<|a12|+|a13|=7+13=20|a33|=5<|a31|+|a32|=12+3=15 Hence it may diverge. Moreover, we can use our R code to test it:

A = matrix(c(3, 1, 2, 7, 5, 3, 13, 3, -5), ncol = 3)
b = matrix(c(76, 28, 1), ncol = 1)
IterSolve(A, b, c(1, 0, 1))$x
# Result
# [1] -2.496896e+172  1.261843e+171 -9.230477e+171
# Warning message:
# In IterSolve(A, b, c(1, 0, 1)) : Maxit reached

2. Solve the following system equations using Gauss-Seidel method. {12x1+7x2+3x3=173x1+6x2+2x3=92x1+7x211x3=49 Choose the initial guess as [x1x2x3]=[135]

Solution:

Firstly, we test whether the coefficient matrix is diagonal dominant: {|a11|=12>|a12|+|a13|=10|a22|=6>|a21|+|a23|=5|a33|=11>|a31|+|a32|=9 which means it is diagonal dominant. Then we will conduct two iterations: I1={x1=177x23x312=177×33×512=1.583333x2=93x12x36=93×(1.583333)2×56=0.625000x3=492x17x211=492×(1.583333)7×0.62500011=4.344697 I2={x1=177x23x312=177×0.6250003×(4.344697)12=2.138258x2=93x12x36=93×2.1382582×(4.344697)6=1.879104x3=492x17x211=492×2.1382587×1.87910411=2.869978 Alternatively, we can use R code to solve it directly:

A = matrix(c(12, 3, 2, 7, 6, 7, 3, 2, -11), ncol = 3)
b = matrix(c(17, 9, 49), ncol = 1)
IterSolve(A, b, c(1, 3, 5), eps = 1e-8)$x
# Result
# Converged after  16 iterations
# [1]  1  2 -3

That is, the solution is [x1x2x3]=[123]

3. Solve the following system equations using Gauss-Seidel method. {3x1+6x2+2x3=912x1+7x2+3x3=172x1+7x211x3=49 Choose the initial guess as [x1x2x3]=[1.12.12.9]

Solution:

We will use the R code to solve it directly:

A = matrix(c(3, 12, 2, 6, 7, 7, 2, 3, -11), ncol = 3)
b = matrix(c(9, 17, 49), ncol = 1)
IterSolve(A, b, c(1, 0, 1), eps = 1e-8)$x
# Result
# Error in IterSolve(A, b, c(1, 3, 5)) : The algorithm diverges

Recall the R function, the result is divergent when the solution in the iterations goes to infinity. Moreover, we can read off its non-convergent according to it is not diagonal dominant since {|a11|=3<|a12|+|a13|=8|a22|=7<|a21|+|a23|=15

posted on   赵胤  阅读(507)  评论(0编辑  收藏  举报

编辑推荐:
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
阅读排行:
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!

导航

统计

点击右上角即可分享
微信分享提示