Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % A-2 Q-1(a)
- A = [5 -1 1
- 2 8 -1
- -1 2 4];
- b = [10
- 11
- 3];
- D = diag(diag(A));
- LU = D - A;
- f = @(x) (D\LU)*x + D\b;
- x0 = [0;0;0];
- x = f(x0);
- while norm(x-x0) > 0.0001
- x0 = x;
- x = f(x);
- end
- disp(x)
- % A-2 Q-1(b)
- A = [5 -1 1
- 2 8 -1
- -1 2 4];
- b = [10
- 11
- 3];
- D = diag(diag(A));
- L = D - tril(A);
- U = D - triu(A);
- f = @(x) ((D-L)\U)*x + (D-L)\b;
- x0 = [0;0;0];
- x = f(x0);
- while norm(x-x0) > 0.0001
- x0 = x;
- x = f(x);
- end
- disp(x)
- % A-2 Q-1(c)
- A = [5 -1 1
- 2 8 -1
- -1 2 4];
- b = [10
- 11
- 3];
- D = diag(diag(A));
- L = D - tril(A);
- U = D - triu(A);
- f = @(x) ((D-L)\U)*x + (D-L)\b;
- x0 = [0;0;0];
- x = f(x0);
- w = 0.5;
- while norm(x-x0) > 0.0001
- t = x0;
- x0 = x;
- x = (1-w)*t + w*f(x);
- end
- disp(x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement