56
Puff! The magic dragon, live by the sea… 第6第 線線線線線線線 Linear Algebraic Equations

Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Embed Size (px)

Citation preview

Page 1: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

第 6章 線性代數方程式Linear Algebraic Equations

Page 2: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

linear

5x-2y=13

7x+3y=24

• Linear ~ dependent variable 不可以有一次以外的次方

Page 3: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

6.1 Elementary Solution Methods

• Successive elimination of variables

• Gauss elimination

Page 4: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Gauss elimination

-x+y+2z=2 (1)

3x-y+z=6 (2)

-x+3y+4z=4 (3)

-x+y+2z=2 (1)

2y+7z=12 (4)

2y+2z=2 (5)

Page 5: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Gauss elimination

-x+y+2z=2 (1)

5z=10 (6)

y=-1 (7)

x=1

Page 6: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Self test p.334

Page 7: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Singular & ill-conditioned problems

1. 3x-4y=5 6x-10y=2 Sol. (7,4)

2. 3x-4y=5 6x-8y=10 Infinite solutions

3. 3x-4y=5 6x-8y=3 empty set

Page 8: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 9: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 10: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Homogeneous equations

6x+ay=0

2x+4y=0

(a-12)y=0

If a~=12, x=0

If a=12, infinite solutions

Page 11: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Ill-conditioned equations

3x-4y=5 (1)

6x-8.002y=3 (2)

(11 y=(3x-5)/4

(11 y=(3x-1.5)/4.001

(x,y)=(4668, 3500)

Very sensitive !

Page 12: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Matrix methods for linear equations

7

5

43

92

7

5

43

92

743

592

2

1

2

1

21

21

bxA

bAx

x

x

x

x

xx

xx

Page 13: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

mn

mnmm

n

n

mn

mnmm

n

n

mnmnmm

nn

nn

b

b

b

x

x

x

aaa

aaa

aaa

b

b

b

x

x

x

aaa

aaa

aaa

bxaxaxa

bxaxaxa

bxaxaxa

2

12

1

21

22221

11211

2

12

1

21

22221

11211

2211

22222121

11212111

bxA

bAx

Page 14: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Determinants 行列式

379

2106

143

A

A=[3,-4,1;6,10,2;9,-7,3];det(A)ans = 0

Page 15: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Determinants and singular problems

• If determinant of A=0, then a singular problem.

• If determinant of A ~= 0

• If determinant of A = 0

Page 16: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Left-division methodA=[3,2,-9;-9,-5,2;6,7,3];det(A)b=[-65;16;5];A\b

ans = 288ans = 2.0000 -4.0000 7.0000

Page 17: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Right-division method

]193[53

26][ 21

xx

d/Cx

dxC

Page 18: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Ex.6.2-2 p.342

• Kirchhoff’s law

• Current conservation at a node

532

421

iii

iii

0

0

0

23355

552244

44111

viRiR

iRiRiR

iRiRv

Page 19: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea… 0

0

0

23355

552244

44111

viRiR

iRiRiR

iRiRv

532

421

iii

iii

Page 20: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

% resist.m% solve the current i_1,i_2,i_3R=[5,100,200,150,250]*1000;v1=100; v2=50;A1=[R(1)+R(4),-R(4),0];A2=[-R(4),R(2)+R(4)+R(5),-

R(5)];A3=[0,R(5),-(R(3)+R(5))];A=[A1;A2;A3];b=[v1;0;v2];current=A\b;disp('The currents are:')disp(current)The currents are: 1.0e-003 *

0.9544 0.3195 0.0664

235325

35254214

124141

)(

0)(

)(

viRRiR

iRiRRRiR

viRiRR

Page 21: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Exercise p.343-345

Page 22: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Matrix inverse

bAxxI

bAAxA

IAAAA

bAx

1

11

11

Page 23: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

An example of Statics

• Derivation of equilibrium equations.

• Solve the linear equations by matlab.

• P.346-348

Page 24: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Ex. 6.2-5

• Check by matlab as well as by hand for an inversion of 2 by 2 matrix.

2x+9y=53x-4y=7

A=[2,9;3,-4];b=[5;7];x=inv(A)*bx = 2.3714 0.0286

Page 25: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 26: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Cramer’s method

• Self test …

Page 27: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

6.4 Underdetermined systems

A=[1,3];

b=6;

x=A\b

x =

0

2

solutionsinfinite

36

631

63

yx

y

x

yx

Page 28: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Underdetermined systems

0A

Page 29: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Matrix rank 矩陣的秩

2rank

1579

43

4437

210

0

379

2106

143

A=[3,-4,1;6,10,2;9,-7,3];rank(A)

ans =

2

Page 30: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Existence and uniqueness of solutions

• Augmented matrix

10862

7935][

10

7,

862

935

][

bA

bA

bA

Page 31: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Existence and uniqueness of solutions

• Augmented matrix

][rank][rankifonlyandif

unknowns) eqns., (11

bAA

bxA

nmmnnm

Page 32: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Singular matrix

0A

Page 33: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Ex 6.4-1

3x-2y+8z=48-6x+5y+z=-129x+4y+2z=24

A=[3,-2,8;-6,5,1;9,4,2];b=[48;-12;24];rank(A)rank([A b])x=A\b

ans =3ans = 3x = 2.0000 -1.0000 5.0000

Page 34: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Ex 6.4-2

2x-4y+5z=-4-4x-2y+3z=42x+6y-8z=0

• A=[2,-4,5;-4,-2,3;2,6,-8];• b=[-4;4;0];• rank(A)• rank([A b])• x=A\b

• ans =• 2• ans =• 2• Warning: Matrix is singu

lar to working precision.• x =• Inf• Inf• Inf

Page 35: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

pinv command & Euclidean norm

• x=pinv(A)*b

x =

-1.2148

0.2074

-0.1481

Page 36: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Ex 6.4-3

• Statically indeterminate problem

Page 37: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

1600

400

0510

111][

1600

400,

0510

111

1600

400

0510

111

0510)4(400,

0400,

3

2

1

3

2

1

21

321

Ab

x

bA

0M

0F

T

T

T

T

T

T

TT

TTT

Page 38: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

32

31

12

2480

80

2320

TT

TT

TT

Page 39: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

A=[1,1,1;10,5,0];b=[400;1600];rank(A)rank([A b])A\bans = 2ans = 2ans = 160.0000 0 240.0000

pinv(A)*b

ans =

93.3333

133.3333

173.3333

Page 40: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Ex 6.4-4, pp.362

2x-4y+5z=-4-4x-2y+3z=42x+6y-8z=0

• x+0y-0.1z=-1.2• 0x+y-1.3z=0.4• 0x+0y+0z=0

A=[2,-4,5;-4,-2,3;2,6,-8];

b=[-4;4;0];

x=pinv(A)*b

rref([A b])

x =

-1.2148

0.2074

-0.1481

ans =

1.0000 0 -0.1000 -1.2000

0 1.0000 -1.3000 0.4000

0 0 0 0

Page 41: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Underdetermined systems

• P.363-364 ex.6.4-55x+3y+3z=403x+3y+4z=30

• x-0.5z=5• y+1.8333z=5

z

y

x

xBA30

40

433

335

A=[5,3,3;3,3,4];

b=[40;30];

rref([A b])

ans =

1.0000 0 -0.5000 5.0000

0 1.0000 1.8333 5.0000

Page 42: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Ex 6.4-6 p.364

100+200=f1+f4

f1+f2=300+200

600+400=f2+f3

f3+f4=300+500

4

3

2

1

800

1000

500

300

1100

0110

0011

1001

f

f

f

f

xbA

bAx

800

200

300

0

800

200

300

0000

1100

1-010

1001

b])rref([A

43

42

41

ff

ff

ff

Page 43: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 44: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 45: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 46: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 47: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 48: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 49: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 50: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 51: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 52: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 53: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 54: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 55: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…

Page 56: Puff! The magic dragon, live by the sea… 第 6 章 線性代數方程式 Linear Algebraic Equations

Puff! The magic dragon, live by the sea…