help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Implementing a Jacobi iterative method for Ax=b


From: Joza
Subject: Implementing a Jacobi iterative method for Ax=b
Date: Sun, 28 Oct 2012 09:38:29 -0700 (PDT)

Hi guys. I am trying to implement an iterative method for solving Ax=b using
the Jacobi method. When I run the code with any tolerance it doesn't end,
however. Any ideas why?

The matrix A is relatively sparse. Should this mean I should do row
permutations on it before the iteration begins?
*********************************************************
function [x iter] = Jacobi(A, b, tolerance)

iter = 0;
n = size(A,1);
x_old = zeros(n,1);
converged = 0;

M = diag(diag(A));
N = M - A;

while ~converged

                x_new = M\(N*x_old + b);
                iter = iter + 1;
                
                if norm(b - A*x_new)/norm(b) < tolerance
                        x = x_new;
                        converged = 1;
                else
                        x_old = x_new;
                end
        
end



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Implementing-a-Jacobi-iterative-method-for-Ax-b-tp4645833.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]