camelCase
camelCase

Reputation: 532

How to calculate iteration Matrix in Gauss Seidel

I am trying to solve a system through Gauss-Seidel Iterative method. But i also want to receive as an answer the iteration matrix that was used. I have this method

function [x0,iter] = gaussSeidel(A,b,iterMax,tol)

D = diag(diag(A));
Lower = -tril(A,-1);
Upper = -triu(A,1);
M = D - Lower;
N = Upper;
n = size(A);
n = n(1);
x0 = ones(n,1);
iter = 1;
for i = 1:1:iterMax
    iter = i;
    x = M\(N*x0+b);
    normC = norm(x-x0,inf);
    x0 = x;

    if normC <tol
        break
    end
end

I want to know whats in the iteration matrix ((D-Lower)^(-1))*Upper, but for that I would have to calculate the inverse, and that's computationally expensive, is there another way to get the value?

Upvotes: 1

Views: 6147

Answers (1)

crbah
crbah

Reputation: 336

"\" is an optimized way of solving linear constant coefficient systems by taking inverse. If you want to see what is the inverse of the coefficient matrix, then you must use

inv(A)

instead of

A\b

There is no way out! Or if you are only dealing with the N th column of the inverse matrix, then you can also use

I=eye(n);
A\I(:,N);

Upvotes: 0

Related Questions