码迷,mamicode.com
首页 > 其他好文 > 详细

矩阵LU分解的高斯消元法

时间:2016-11-20 19:16:57      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:5.0   高斯消元法   过程   class   消元   mat   矩阵   highlight   高斯   

A=[1,-1,1,-4;5,-4,3,12;2,1,1,11;2,-1,7,-1]
L=eye(length(A))
%开始消元过程
for k=1:(length(A))
   a=A(k,k)
   for i=k+1:(length(A))
      c=-A(i,k)
	  L(i,k)=-c./a
	  for j=1: (length(A))
		A(i,j)=A(i,j)+c.*A(k,j)./ a
	  end
   end
end
L
U=A

A =

     1    -1     1    -4
     5    -4     3    12
     2     1     1    11
     2    -1     7    -1


L =

     1     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1


a =

     1


c =

    -5


L =

     1     0     0     0
     5     1     0     0
     0     0     1     0
     0     0     0     1


A =

     1    -1     1    -4
     0    -4     3    12
     2     1     1    11
     2    -1     7    -1


A =

     1    -1     1    -4
     0     1     3    12
     2     1     1    11
     2    -1     7    -1


A =

     1    -1     1    -4
     0     1    -2    12
     2     1     1    11
     2    -1     7    -1


A =

     1    -1     1    -4
     0     1    -2    32
     2     1     1    11
     2    -1     7    -1


c =

    -2


L =

     1     0     0     0
     5     1     0     0
     2     0     1     0
     0     0     0     1


A =

     1    -1     1    -4
     0     1    -2    32
     0     1     1    11
     2    -1     7    -1


A =

     1    -1     1    -4
     0     1    -2    32
     0     3     1    11
     2    -1     7    -1


A =

     1    -1     1    -4
     0     1    -2    32
     0     3    -1    11
     2    -1     7    -1


A =

     1    -1     1    -4
     0     1    -2    32
     0     3    -1    19
     2    -1     7    -1


c =

    -2


L =

     1     0     0     0
     5     1     0     0
     2     0     1     0
     2     0     0     1


A =

     1    -1     1    -4
     0     1    -2    32
     0     3    -1    19
     0    -1     7    -1


A =

     1    -1     1    -4
     0     1    -2    32
     0     3    -1    19
     0     1     7    -1


A =

     1    -1     1    -4
     0     1    -2    32
     0     3    -1    19
     0     1     5    -1


A =

     1    -1     1    -4
     0     1    -2    32
     0     3    -1    19
     0     1     5     7


a =

     1


c =

    -3


L =

     1     0     0     0
     5     1     0     0
     2     3     1     0
     2     0     0     1


A =

     1    -1     1    -4
     0     1    -2    32
     0     3    -1    19
     0     1     5     7


A =

     1    -1     1    -4
     0     1    -2    32
     0     0    -1    19
     0     1     5     7


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5    19
     0     1     5     7


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5   -77
     0     1     5     7


c =

    -1


L =

     1     0     0     0
     5     1     0     0
     2     3     1     0
     2     1     0     1


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5   -77
     0     1     5     7


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5   -77
     0     0     5     7


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5   -77
     0     0     7     7


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5   -77
     0     0     7   -25


a =

     5


c =

    -7


L =

    1.0000         0         0         0
    5.0000    1.0000         0         0
    2.0000    3.0000    1.0000         0
    2.0000    1.0000    1.4000    1.0000


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5   -77
     0     0     7   -25


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5   -77
     0     0     7   -25


A =

     1    -1     1    -4
     0     1    -2    32
     0     0     5   -77
     0     0     0   -25


A =

    1.0000   -1.0000    1.0000   -4.0000
         0    1.0000   -2.0000   32.0000
         0         0    5.0000  -77.0000
         0         0         0   82.8000


a =

   82.8000


L =

    1.0000         0         0         0
    5.0000    1.0000         0         0
    2.0000    3.0000    1.0000         0
    2.0000    1.0000    1.4000    1.0000


U =

    1.0000   -1.0000    1.0000   -4.0000
         0    1.0000   -2.0000   32.0000
         0         0    5.0000  -77.0000
         0         0         0   82.8000

>> A=L*U

A =

     1    -1     1    -4
     5    -4     3    12
     2     1     1    11
     2    -1     7    -1

  

矩阵LU分解的高斯消元法

标签:5.0   高斯消元法   过程   class   消元   mat   矩阵   highlight   高斯   

原文地址:http://www.cnblogs.com/mubu/p/6082857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!