a = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 - electrical and computer...

6
Error Analysis 2 A = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 0, 11, 0, -4, -1, 0, -6, 0, 0, 0 -5, 0, 7, -2, 0, 0, 0, 0, 0, 0 0, -4, -2, 7, 0, 0, 0, 0, 0, -1 -2, -1, 0, 0, 3, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 2, -2, 0, 0, 0 0, -6, 0, 0, 0, -2, 8, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 5, -5, 0 0, 0, 0, 0, 0, 0, 0, -5, 8, -3 -1, 0, 0, -1, 0, 0, 0, 0, -3, 5 + 1.0e-15]; A1 = A; b = [ 1 -1 1 -1 1 -1 2 -2 10 -10.1]'; % solve using L1*D1*U1 x1 = b1 (where b1 = b) b1 = b; b1p = L1\b1; b1pp=D1\b1p; x1=U1\b1pp; % solve using LP*UP = P*A1, then A1 x2 = b2 => P*A1 x2 = P*b2 % or LP*UP x2 = P*b2 b2 = b; [LP,UP,P] = lu(A1); b2p=LP\(P*b2); x2=UP\b2p; % now solve by matrix inversion x3 = inv(A1)*b; % now solve by matlab linear eq solver x4 = A1\b; % now solve by QR (Orthogonal) algorithm [Q,R]=qr(A1); y=Q'*b; x5=R\y;

Upload: vuongtuyen

Post on 06-Mar-2018

222 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: A = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 - Electrical and Computer ...people.ece.umn.edu/class/ee8725/Error analysis 2.doc · Web view0, 11, 0, -4, -1, 0, -6, 0, 0, 0-5, 0, 7, -2, 0,

Error Analysis 2

A = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 0, 11, 0, -4, -1, 0, -6, 0, 0, 0 -5, 0, 7, -2, 0, 0, 0, 0, 0, 0 0, -4, -2, 7, 0, 0, 0, 0, 0, -1 -2, -1, 0, 0, 3, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 2, -2, 0, 0, 0 0, -6, 0, 0, 0, -2, 8, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 5, -5, 0 0, 0, 0, 0, 0, 0, 0, -5, 8, -3 -1, 0, 0, -1, 0, 0, 0, 0, -3, 5 + 1.0e-15];

A1 = A;

b = [ 1 -1 1 -1 1 -1 2 -2 10 -10.1]';

% solve using L1*D1*U1 x1 = b1 (where b1 = b)

b1 = b;

b1p = L1\b1;b1pp=D1\b1p;x1=U1\b1pp;

% solve using LP*UP = P*A1, then A1 x2 = b2 => P*A1 x2 = P*b2% or LP*UP x2 = P*b2

b2 = b;

[LP,UP,P] = lu(A1);

b2p=LP\(P*b2);x2=UP\b2p;

% now solve by matrix inversion

x3 = inv(A1)*b;

% now solve by matlab linear eq solver

x4 = A1\b;

% now solve by QR (Orthogonal) algorithm

[Q,R]=qr(A1);

y=Q'*b;x5=R\y;

solution1 = A1*x1

solution2 = A1*x2

solution3 = A1*x3

solution4 = A1*x4

Page 2: A = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 - Electrical and Computer ...people.ece.umn.edu/class/ee8725/Error analysis 2.doc · Web view0, 11, 0, -4, -1, 0, -6, 0, 0, 0-5, 0, 7, -2, 0,

Error Analysis 2

solution5 = A1*x5

x1x2x3x4x5

max_error1 = norm(solution1-b,inf)max_error2 = norm(solution2-b,inf)max_error3 = norm(solution3-b,inf)max_error4 = norm(solution4-b,inf)max_error5 = norm(solution5-b,inf)

Page 3: A = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 - Electrical and Computer ...people.ece.umn.edu/class/ee8725/Error analysis 2.doc · Web view0, 11, 0, -4, -1, 0, -6, 0, 0, 0-5, 0, 7, -2, 0,

Error Analysis 2

A1*x1 =

0.9688 -1.1094 1.0156 -0.9844 1.0156 -1.0000 2.1250 -2.0312 10.0469 -10.1469

A1*x2 =

0.9844 -0.9375 1.0156 -1.0312 1.0000 -1.0000 2.0312 -1.9531 9.9688 -10.1448

A1*x3 =

-1.2344 -0.5312 2.8906 -2.5000 1.8125 -1.0000 1.7500 -2.5000 11.5000 -10.2542

A1*x4 =

1.2344 -1.1875 0.8906 -0.8906 1.0000 -0.9688 2.0000 -2.0312 9.9062 -10.0531

Page 4: A = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 - Electrical and Computer ...people.ece.umn.edu/class/ee8725/Error analysis 2.doc · Web view0, 11, 0, -4, -1, 0, -6, 0, 0, 0-5, 0, 7, -2, 0,

Error Analysis 2

A1*x5 =

0.8281 -0.7188 1.1719 -1.0938 1.0625 -1.0000 2.0312 -2.2656 10.0469 -10.1862

x1 =

1.0e+014 *

-1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259

x2 =

1.0e+013 *

-7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060

x3 =

1.0e+013 *

Page 5: A = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 - Electrical and Computer ...people.ece.umn.edu/class/ee8725/Error analysis 2.doc · Web view0, 11, 0, -4, -1, 0, -6, 0, 0, 0-5, 0, 7, -2, 0,

Error Analysis 2

-7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060 -7.5060

x4 =

1.0e+014 *

-1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259 -1.1259

x5 =

1.0e+014 *

-1.3922 -1.3922 -1.3922 -1.3922 -1.3922 -1.3922 -1.3922 -1.3922 -1.3922 -1.3922

max_error1 =

0.1250

max_error2 =

0.0625

max_error3 =

Page 6: A = [ 8, 0, -5, 0, -2, 0, 0, 0, 0, -1 - Electrical and Computer ...people.ece.umn.edu/class/ee8725/Error analysis 2.doc · Web view0, 11, 0, -4, -1, 0, -6, 0, 0, 0-5, 0, 7, -2, 0,

Error Analysis 2

2.2344

max_error4 =

0.2344

max_error5 =

0.2812