+ All Categories
Home > Documents > 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 ·...

9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 ·...

Date post: 20-May-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
21
2017-10-19 1 9장 Gauss 소거법 9.1 소규모의 방정식을 풀기 9.2 순수 Gauss 소거법 9.3 피봇팅 9.4 삼중대각 시스템 Applied Numerical Methods Applied Numerical Methods 9장 Gauss 소거법 9장 Gauss 소거법 어떤 원리에 의해 다음과 같은 MATLAB 명령어가 수행되는가? >> x=A\b >> x=inv(A)*b
Transcript
Page 1: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

1

9장 Gauss 소거법

9.1 소규모의 방정식을 풀기

9.2 순수 Gauss 소거법

9.3 피봇팅

9.4 삼중대각 시스템

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9장 Gauss 소거법

어떤 원리에 의해 다음과 같은MATLAB 명령어가 수행되는가?

>> x=A\b

>> x=inv(A)*b

Page 2: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

2

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.1 소규모의 방정식을 풀기 (1/6)

컴퓨터를 필요로 하지 않고 소규모 연립방정식

(n≤3)에 적합한 방법

- 도식적 방법, Cramer 공식, 미지수 소거법

도식적인 방법

221823

21

21

=+-=+

xxxx

121

923

12

12

+=

+-=

xx

xx

두 연립선형대수방정식의 도식적인 해(교점이 해를 나타냄)

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.1 소규모의 방정식을 풀기 (2/6)

특이 평행선 ® 해가 없음

두 선이 일치함 ® 해가 무한히 많음

불량조건 특이에 가까워 반올림오차에 매우 민감함

특이 시스템과 불량조건 시스템의 도식적 표현

(a) 해가 없음, (b) 해가 무한히 많음, (c) 해를 식별하기 어려움.

Page 3: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

3

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.1 소규모의 방정식을 풀기 (3/6)

행렬식과 Cramer 공식세 개의 방정식에 대한 행렬식을 고려하자.

여기서

이 시스템의 행렬식은 계수행렬로부터 구성되는데 다음과 같다.

}{}]{[ bxA =úúú

û

ù

êêê

ë

é=

333231

232221

131211

][aaaaaaaaa

A

)()()( 312232211331233321123223332211

3231

222113

3331

232112

minor

3332

232211

333231

232221

131211

aaaaaaaaaaaaaaa

aaaa

aaaaa

aaaaa

aaaaaaaaaa

D

-+---=

+-==

48476

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.1

Q. 다음 시스템에 대하여 행렬식을 구하라.

풀이)

îíì

=+-=+

221823

21

21

xxxx

ïïî

ïïí

ì

=+-

=+-

21

21

121

21

21

xx

xx

ïî

ïíì

=+-

=+-

22

121

21

21

xx

xx

ïïî

ïïí

ì

=+-

=+-

121

1.153.2

21

21

xx

xx

8)1(2)2(32123

=--=-

=D 0211)1(

21

121

121

=÷øö

çèæ ---=

-

-=D

0)1(1)2(21

21

121

=---=-

-=D 04.05

3.21)1(21

153.2

121

-=÷øö

çèæ ---=

-

-=D

불량조건

특이조건

특이조건

Page 4: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

4

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.1 소규모의 방정식을 풀기 (4/6)

특이 시스템 ® 행렬식 = 0

불량조건 시스템 ® 행렬식이 0에 가까움

Cramer 공식

Daabaabaab

x 33323

23222

13121

1 =

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.2 (1/2)

Q. Cramer 공식으로 다음의 연립방정식을 풀어라.

풀이)

44.05.03.0 1.067.0 9.1 5.001.0 52.03.0

321

321

321

-=++=++

-=++

xxxxxxxxx

0022.03.01.0

15.01

5.01.09.15.0

52.05.03.09.11

3.0 -=+-=D

Page 5: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

5

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.2 (2/2)

풀이)

9.140022.0

03278.00022.0

5.03.044.09.1167.0

152.001.0

1 -=-

=-

-

-

=x

5.290022.0

0649.00022.0

5.044.01.09.167.05.0

101.03.0

2 -=-

=-

-

-

=x

8.190022.0

04256.00022.0

44.03.01.067.015.001.052.03.0

3 -=--

=-

-

-

=x

Cramer 공식은 n > 3 이면 비현실적 이다.

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.1 소규모의 방정식을 풀기 (5/6)

미지수 소거법두 개의 방정식으로 구성된 경우를 고려해 보자.

상수를 곱하면

뺄셈으로 x1을 소거하면

따라서 이 결과를 대입하면

2222121

1212111

bxaxabxaxa

=+=+

2112221112111

1212122111121

baxaaxaabaxaaxaa

=+=+

1212112122122211 babaxaaxaa -=-

12212211

1212112 aaaa

babax--

=12212211

2121221 aaaa

babax--

=

Page 6: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

6

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.1 소규모의 방정식을 풀기 (6/6)

미지수 소거법은 Cramer 공식을 그대로 따른 것이다.

이 기법은 컴퓨터를 이용하도록 공식화되어 있어

프로그램 작성이 용이하다.

12212211

212122

2221

1211

222

121

1 aaaababa

aaaaabab

x--

==

12212211

121211

2221

1211

221

111

2 aaaababa

aaaababa

x--

==

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (1/14)

Gauss 소거법의 두 단계: 전진소거와 후진대입

� 하나의 방정식에

오직 하나의 미지수만 나타나도록

방정식을 조작한다.

‚ 그 미지수를 풀고,

후진대입을 통해

나머지 미지수도 결정한다.

Page 7: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

7

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (2/14)

알고리즘을 개발하면 대규모의 방정식으로

확장이 가능하다.

Gauss 소거법은 가장 기본적인 알고리즘이다.

"순수" Gauss 소거법은 0으로 나누는 경우를

극복하지 못한 방법이다.

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (3/14)

n 개의 미지수를 가진 방정식을 다루어 보자.

nnnnnnn

n

n

bxaxaxaxa

bxaxaxaxabxaxaxaxa

=++++

=++++=++++

L

MM

L

L

332211

222223222121

111113112111

피봇원소 (첫 번째 방정식의 미지수의 계수)

(

번째

미지수에

대한)

피봇방정식

Page 8: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

8

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (4/14)

단계 �: 미지수의 전진소거(방정식을 상삼각시스템으로 바꿈)

두 번째에서 n번째 방정식까지 미지수 x1을 소거한다.

첫 번째 식에 a21/a11을 곱하면

두 번째 식에서 빼면

또는

111

211

11

21313

11

21212

11

21121 b

aaxa

aaxa

aaxa

aaxa nn =++++ L

111

2121

11

212212

11

2122 b

aabxa

aaaxa

aaa nnn -=÷÷

ø

öççè

æ-++÷÷

ø

öççè

æ- L

'2

'22

'22 bxaxa nn =++L

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (5/14)

나머지 방정식에서도 대해 반복하면

두 번째 피봇방정식을 이용하여 미지수 x2를 소거하면

''3

'32

'2

'3

'33

'332

'32

'2

'23

'232

'22

11313212111

nnnnnn

nn

nn

nn

bxaxaxa

bxaxaxabxaxaxabxaxaxaxa

=+++

=+++=+++=++++

L

MM

L

L

L

""3

"3

"3

"33

"33

'2

'23

'232

'22

11313212111

nnnnn

nn

nn

nn

bxaxa

bxaxabxaxaxabxaxaxaxa

=++

=++=+++=++++

L

MM

L

L

L

Page 9: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

9

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (6/14)

나머지 피봇방정식을 이용하여 계속적으로 소거를 수행하면상삼각행렬 시스템을 구성할 수 있다.

)1()1(

"3

"33

"33

'2

'23

'232

'22

11313212111

-- =

=++=+++=++++

nnn

nnn

nn

nn

nn

bxa

bxaxabxaxaxabxaxaxaxa

MO

L

L

L

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (7/14)

단계 ‚: 후진대입

(i = n-1, n-2, ¼,1)

)1(

)1(

-

-

= nnn

nn

n abx

)1(1

)1()1(

-

+=

-- å-= i

ii

n

ijj

iij

ii

i a

xabx

Page 10: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

10

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.3 (1/2)

Q. Gauss 소거법을 이용하여 방정식을 풀어라.(정해는 x1 = 3, x2 = -2.5, 그리고 x3 = 7)

풀이) 전진소거를 수행하면

4.71 10 .203.03.193.07 1.085.7 0.21.03

321

321

321

=+--=-+

=--

xxxxxxxxx

6150.70 0200.10 190000.0 5617.19293333.07.00333 85.7 0.2 1.0 3

32

32

321

=+--=-

=--

xxxxxxx

0843.70 0120.10 5617.19293333.07.00333 85.7 0.2 1.0 3

3

32

321

=-=-

=--

xxxxxx

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.3 (2/2)

풀이) 후진대입하여 해를 구하면

결과를 확인하면

00003.70120.100843.70

3 ==x

50000.200333.7

)00003.7(293333.05617.192 -=

+-=x

00000.33

)00003.7(2.0)50000.2(1.085.71 =

+-+=x

4.714003.71)00003.7(10)5.2(2.0)3(3.03.1930000.19)00003.7(3.0)5.2(7)3(1.0

85.784999.7)00003.7(2.0)5.2(1.0)3(3

@=+---@-=--+

@=---

결과를 확인하면

Page 11: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

11

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (8/14)

[순수 Gauss 소거법을 수행하는 M-파일 ]

function x = GaussNaive(A,b)

% GaussNaive (A,b):

% Gauss elimination without pivoting

% input:

% A = coefficient matrix

% b = right hand side vector

% output:

% x = solution vector

[m,n] = size(A);

if m ~= n, error('Matrix A must be square'); end

nb = n+1;

Aug =[A b];

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (8/14)

[순수 Gauss 소거법을 수행하는 M-파일 ]

% forward elimination

for k = 1:n-1

for i = k+1:n

factor = Aug(i,k)/Aug(k,k);

Aug(i,k:nb) = Aug(i,k:nb)-factor*Aug(k,k:nb);

end

end

% back substitution

x = zeros(n,1);

x(n) = Aug(n,nb)/Aug(n,n);

for i = n-1:-1:1

x(i) = (Aug(i,nb)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i);

end

Page 12: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

12

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (9/14)

연산 횟수수행시간 ~ 부동소수점 연산(flops)의 횟수

몇 개의 항들을 정의하면

åå==

=m

i

m

iifcicf

11)()( { } ååå

===

+=+m

i

m

i

m

iigifigif

111)()()()(

mm

i=++++=å

=

111111

L 11 +-=å=

kmm

ki

)(22

)1(3212

1mOmmmmi

m

i+=

+=++++=å

=

L

)(36

)12)(1(321 23

2222

1

2 mOmmmmmim

i+=

++=++++=å

=

L

여기서 O(m n) = 크기가 m n 차수와 그보다 낮은 차수의 항

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (10/14)

순수 Gauss 소거법의 M-파일에 대하여

외부 루프가 k = 1에서 시작하므로,

내부 루프의 한계는 i = 2 에서부터 n까지다.

따라서 내부 루프의 반복 횟수는

· ( n – 1)번 반복하는 내부 루프에 대해서

- 나눗셈 한 번

- 각각의 열 요소에 대해 2 에서 nb까지 곱셈 (n + 1까지 n 번의 곱셈)

- 마찬가지로 n 번 뺄셈

- 합하면 n + 1 번 곱셈/나눗셈과 n 번 뺄셈

- 외부 루프를 한 번 지나는 것에 대해

전체적으로 (n – 1)(n + 1)번 곱셈/나눗셈과 (n – 1)(n)번 뺄셈

11212

-=+-=å=

nnn

i

Page 13: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

13

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (11/14)

요약하면외부 루프

k내부 루프

i덧셈/뺄셈 연산횟수 곱셈/나눗셈 연산횟수

1 2, n (n – 1)(n) (n – 1)(n + 1)

2 3, n (n – 2)(n – 1) (n – 2)(n)

⋮ ⋮ ⋮ ⋮

k k + 1, n (n – k)(n + 1 – k) (n – k)(n + k -2)

⋮ ⋮ ⋮ ⋮

n – 1 n, n (1)(2) (1)(3)

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (12/14)

따라서 소거를 위한 전체 덧셈/뺄셈 연산횟수는

또는

결과적으로 다음과 같다.

유사한 해석을 곱셈/나눗셈에 대해서 수행하면

åå-

=

-

=

++-+=-+-1

1

21

1])12()1([)1)((

n

k

n

kknknnknkn

ååå-

=

-

=

-

=

++-+1

1

21

1

1

1)12(1)1(

n

k

n

k

n

kkknnn

)(3

)(31)]([)]([

323233 nOnnOnnOnnOn +=úûù

êëé +++-+

)(3

)(31)]([)]([ 2

323323 nOnnOnnOnnOn +=úûù

êëé +++-+

Page 14: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

14

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (13/14)

최종적으로

O(n2) 이하의 항들은 n이 증가할수록 무시됨을 유의하라..

후진대입에 대하여

덧셈/뺄셈 연산횟수 = n(n – 1)/2

곱셈/나눗셈 연산횟수 = n(n + 1)/2

따라서 합은

)(3

2 23

nOn+

)(2 nOn +

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.2 순수 Gauss 소거법 (14/14)

순수 Gauss 소거법에 소요되는 전체 연산횟수는 다음과 같다.

� 시스템이 커질수록 연산시간이 크게 증가한다.

‚ 대부분의 연산은 소거단계에서 발생한다.

)(3

2)()(3

2 23

increasesn as

onsubstitutiBack

2

neliminatioForward

23

nOnnOnnOn+¾¾¾¾ ®¾+++

443442144 344 21

n 전진소거 후진대입 전체연산횟수 2n3/3 소거의비율%

10100

1000

705671550

6.67 ´ 108

100100001 ´ 106

805681550

6.68 ´ 108

667666667

6.67 ´ 108

87.58%98.53%99.85%

Page 15: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

15

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.3 피봇팅 (1/3)

® 순수 Gauss 소거법의 정규화에서

0으로 나누는 나눗셈 발생!

피봇 원소가 0에 가까우면 어떤 일이 일어나는가?

L 피봇 원소의 크기가 다른 원소에 비해 작으면 반올림오차가 개입!

처방

þ 각각의 행을 정규화하기 전에 해당 열에서 계수가 가장 큰 것을 찾는다.

þ 가장 큰 원소가 피봇 원소가 되도록 순서를 바꾼다Þ 부분 피봇팅

þ 열과 행에서 가장 큰 원소를 찾아 순서를 바꾼다

Þ 완전 피봇팅 ® 드물게 사용됨

5 63237648 32

321

321

32

=+--=++

=+

xxxxxxxx

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.4 (부분 피봇팅) (1/3)

Q. Gauss 소거법을 이용하여 다음의 방정식을 풀어라.

첫 번째 피봇 원소는 a11 = 0.0003이며, 0에 매우 가깝다. 그래서 방정식의 순서를 바꾸는 부분 피봇팅을 취한다. 정해는 x1 = 1/3과 x2 = 2/3이다.

0000.10000.10000.10001.20000.30003.0

21

21

=+=+

xxxx

Page 16: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

16

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.4 (부분 피봇팅) (2/3)

풀이) 첫 번째 식에 1/(0.0003)을 곱하면

®

두 번째 식에서 이 식을 빼면 결과는

® ® x2 = 2/3

따라서

6667000,10 21 =+ xx

66669999 2 -=- x

0003.0)3/2(30001.2

1-

=x

유효숫자수 x2 x1x1의백분율

상대오차의절대값

34567

0.6670.66670.666670.6666670.6666667

-3.330.00000.300000.3300000.3330000

10991001010.1

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.4 (부분 피봇팅) (3/3)

거의 같은 두 수 사이의 뺄셈으로 인해 결과가 유효숫자 수에

매우 민감하다.

순서를 바꾸어서 방정식을 풀면

(= 부분 피봇팅)

® x2 = 2/3 그리고

유효숫자수 x2 x1x1의백분율

상대오차의절대값

34567

0.6670.66670.666670.6666670.6666667

0.3330.33330.333330.3333330.3333333

0.10.010.0010.00010.00001

0001.20000.30003.00000.10000.10000.1

21

21

=+=+

xxxx

1)3/2(1

1-

=x

Page 17: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

17

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.3 피봇팅 (2/3)

[부분 피봇팅이 포함된 Gauss 소거법을 위한 M-파일 ]

function x = GaussPivot(A,b)

% GaussPivot (A,b):

% Gauss elimination with partial pivoting

% input:

% A = coefficient matrix

% b = right hand side vector

% output:

% x = solution vector

[m,n] = size(A);

if m ~= n, error('Matrix A must be square'); end

nb = n+1;

Aug =[A b];

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.3 피봇팅 (2/3)

[부분 피봇팅이 포함된 Gauss 소거법을 위한 M-파일 ]

% forward elimination

for k = 1:n-1

% partial pivoting

[big, i] = max(abs(Aug(k:n,k)));

ipr = i + k -1;

if ipr ~= k

% pivot the row

Aug([k,ipr],:) = Aug([ipr,k],:);

end

Page 18: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

18

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.3 피봇팅 (2/3)

[부분 피봇팅이 포함된 Gauss 소거법을 위한 M-파일 ]

for i = k+1:n

factor = Aug(i,k)/Aug(k,k);

Aug(i,k:nb) = Aug(i,k:nb)-factor*Aug(k,k:nb);

end

end

% back substitution

x = zeros(n,1);

x(n) = Aug(n,nb)/Aug(n,n);

for i = n-1:-1:1

x(i) = (Aug(i,nb)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i);

end

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.3 피봇팅 (3/3)

>> y = [1; 3; 5; 2; 4];

>> [ymax, imax] =max(y)

ymax =

5

imax =

3

>> A=[0.0003 3; 1 1]; b=[2.0001; 1];

>> x = GaussPivot(A,b)

x =

0.3333

0.6667

Page 19: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

19

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.4 삼중대각 시스템 (1/3)

띠의 폭이 3인 삼중대각 시스템을 고려하자.

ïïïïï

þ

ïïïïï

ý

ü

ïïïïï

î

ïïïïï

í

ì

×××

=

ïïïïï

þ

ïïïïï

ý

ü

ïïïïï

î

ïïïïï

í

ì

×××

úúúúúúúúúúú

û

ù

êêêêêêêêêêê

ë

é

××××××

×××

-----

n

n

n

n

nn

nnn

rr

rrr

xx

xxx

fegfe

gfegfe

gf

1

3

2

1

1

3

2

1

111

333

222

11

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.5 (삼중대각 시스템의 해) (1/2)

Q. 다음의 삼중대각 시스템의 해를 구하라.

ïïþ

ïïý

ü

ïïî

ïïí

ì

=

ïïþ

ïïý

ü

ïïî

ïïí

ì

úúúú

û

ù

êêêê

ë

é

---

---

8.408.08.08.40

04.21104.21

104.21104.2

4

3

2

1

xxxx

Page 20: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

20

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

예제 9.5 (삼중대각 시스템의 해) (2/2)

풀이)

전진소거를 통해

후진대입으로

해를 구하면

ïïþ

ïïý

ü

ïïî

ïïí

ì

=

ïïþ

ïïý

ü

ïïî

ïïí

ì

úúúú

û

ù

êêêê

ë

é

--

-

996.50221.14

8.208.40

323.11395.1

1550.1104.2

4

3

2

1

xxxx

545.38040.2

832.37)1(800.40

832.37550.1

832.37)1(800.20

832.37395.1

545.38)1(221.14

545.38323.1996.50

1

2111

2

3222

3

4333

4

44

=--

=-

=

=--

=-

=

=--

=-

=

===

fxgrx

fxgrx

fxgrx

frx

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.4 삼중대각 시스템 (2/3)

[상삼각 시스템을 풀기 위한 M-파일]

function x = Tridiag(e, f, g, r)

% Tridiag(e, f, g, r):

% Tridiagonal system solver

% input:

% e = subdiagonal vector

% f = diagonal vector

% g = superdiagonal vector

% r = right hand side vector

% output

% x = solution vector

Page 21: 9장Gauss 소거법 - DAEGUneslab.daegu.ac.kr/lec/numanalysis-doc/ppt/chap09.pdf · 2017-10-19 · 9.2 순수Gauss 소거법(2/14) 알고리즘을개발하면대규모의방정식으로

2017-10-19

21

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.4 삼중대각 시스템 (2/3)

[상삼각 시스템을 풀기 위한 M-파일]

n = length(f);

% forward elimination

for k = 2:n

factor = e(k)/f(k-1);

f(k) = f(k) - factor*g(k-1);

r(k) = r(k) - factor*r(k-1);

end

% back substitution

disp(f); disp(r) % check modified coefficients

x(n) = r(n)/f(n);

for k = n-1:-1:1

x(k) = (r(k)-g(k)*x(k+1))/f(k);

end

Applied Numerical MethodsApplied Numerical Methods 9장 Gauss 소거법

9.4 삼중대각 시스템 (3/3)

>> e=[0; -1; -1; -1];

>> f=[2.04; 2.04; 2.04; 2.04];

>> g=[-1; -1; -1; 0];

>> r=[40.8; 0.8; 0.8; 40.8];

>> x = Tridiag(e, f, g, r)

2.0400 1.5498 1.3948 1.3230

40.8000 20.8000 14.2211 50.9961

x =

38.5449 37.8317 37.8317 38.5449

· 대부분의 상삼각 시스템에서는 피봇팅이 필요하지 않으나드물게 요구되는 경우도 있다.

· 상삼각 시스템에 소요되는 계산 노력~ n (참고로 Gauss 소거법 ~ n3)


Recommended