1. (10 points) Consider the linear system, 20x 1 ? 5x 2 + 18x 3 = 2 (a) Verify t
ID: 2262793 • Letter: 1
Question
1. (10 points) Consider the linear system,
20x1 ? 5x2 + 18x3 = 2
(a) Verify that the Jacobi method is not convergent by computing 10 iterations and evaluating the residual in the l2-norm for each iteration. Show your results.
(b) Consider the damped Jacobi method given by
x (k+1) = (1 ? ?)x (k) + ?D?1 [ b ? (L + U)x (k) ]
with 0 < ? < 1. Write a program that implements the damped Jacobi method given A, b and ?. Use it to find a value ? for which the damped Jacobi method is convergent (try a couple of values until you find one). Clearly state the stopping criteria you used, the number of iterations taken by the method and the approximate solution obtained.
Explanation / Answer
clear all;
clc;
n=3;
A=[20 -5 18;-1 3 -1; 9 -10 10];
b=[2; 3 ;-2];
x=[1 0 0];
[n,m]=size(A);
t=1;
while(t<10)
for i=1:n
y(i)=(b(i)-A(i,1:i-1)*x(1:i-1)'-A(i,i+1:n)*x(i+1:n)')/A(i,i);
end
err=norm(x-y);
x=y;
t=t+1;
end
t
x'
err'
t =
10
ans =
-4.7337
3.4059
-2.4598
ans =
10.9276
B)
clear all;
clc;
n=3;
A=[20 -5 18;-1 3 -1; 9 -10 10];
b=[2; 3 ;-2];
L=[0 0 0;A(2,1) 0 0;A(3,1) A(3,2) 0];
U=[0 A(1,2) A(1,3);0 0 A(2,3); 0 0 0];
D=[A(1,1) 0 0;0 A(2,2) 0; 0 0 A(3,3)];
D1=inv(D);
x=[1 ;0 ;0];
thi=0.7;
err=0.1;
t=1;
while(err>1e-5)
y=(1-thi)*x+thi*(D1*(b-(L+U)*x));
err=norm(x-y);
x=y;
t=t+1;
end
disp(' Solution')
x
disp('Number of iterations')
t
disp('error')
err'
Solution
x =
-2.8314
1.2584
3.6067
Number of iterations
t =
150
error
ans =
9.4342e-06
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.