Benjamin
08-07-2008, 12:13 AM
Hi,
I have just started learning how to use Matlab and I am having trouble with this particular question. It'd be great if you can help me out with this. I have solved part (a) and (b) of the question but I am having trouble with part (c), the matlab related part :(:(:(. The question is as follows:
Consider a n by n tridiagonal matrix A where there is 3 on the diagonal and -1 on the sub- and super-diagonal. For eg, when n=4 the matrix will be
[ 3 -1 0 0;-1 3 -1 0;0 -1 3 -1;0 0 -1 3]. Let b be the vector where bi = 1/i.
(a) For n=4, find the value of T for the Jacobi method, and find ||T||inf.
(b) Will the norm be any different for a large value of n?
(c) For n=25, write a Matlab script file to perform 4 iterations of Jacobi method to estimate the solution of Ax=b. Use the zero vector for your first estimate.
Answers:
(a) T=[0 1/3 0 0;1/3 0 1/3 0;0 1/3 0 1/3;0 0 1/3 0] and the ||T||inf = 2/3
(b) No the norm will not be any different for a larger value of n.
Now for part (c) I wrote the Jacobi function but was told to write another simpler Jacobi function that does not do unnecessary multiplications! My function is as follows:
function y = jacobi (A,b,y,N)
% This function applies N iterations of Jacobi's method
% to the system of linear equations Ax = b.
y=[0,0,0,0]';
n = length(y);
for k=1:N
for i=1:n
sum = b(i);
for j=1:i-1
sum = sum - A(i,j)*y(j);
end
for j = i+1:n
sum = sum - A(i,j)*y(j);
end
x(i) = sum/A(i,i);
end
y = x';
end
Can you please help me out with making this simpler? I am new to Matlab so I am not very good. Thanks!
I have just started learning how to use Matlab and I am having trouble with this particular question. It'd be great if you can help me out with this. I have solved part (a) and (b) of the question but I am having trouble with part (c), the matlab related part :(:(:(. The question is as follows:
Consider a n by n tridiagonal matrix A where there is 3 on the diagonal and -1 on the sub- and super-diagonal. For eg, when n=4 the matrix will be
[ 3 -1 0 0;-1 3 -1 0;0 -1 3 -1;0 0 -1 3]. Let b be the vector where bi = 1/i.
(a) For n=4, find the value of T for the Jacobi method, and find ||T||inf.
(b) Will the norm be any different for a large value of n?
(c) For n=25, write a Matlab script file to perform 4 iterations of Jacobi method to estimate the solution of Ax=b. Use the zero vector for your first estimate.
Answers:
(a) T=[0 1/3 0 0;1/3 0 1/3 0;0 1/3 0 1/3;0 0 1/3 0] and the ||T||inf = 2/3
(b) No the norm will not be any different for a larger value of n.
Now for part (c) I wrote the Jacobi function but was told to write another simpler Jacobi function that does not do unnecessary multiplications! My function is as follows:
function y = jacobi (A,b,y,N)
% This function applies N iterations of Jacobi's method
% to the system of linear equations Ax = b.
y=[0,0,0,0]';
n = length(y);
for k=1:N
for i=1:n
sum = b(i);
for j=1:i-1
sum = sum - A(i,j)*y(j);
end
for j = i+1:n
sum = sum - A(i,j)*y(j);
end
x(i) = sum/A(i,i);
end
y = x';
end
Can you please help me out with making this simpler? I am new to Matlab so I am not very good. Thanks!