help-octave
[Top][All Lists]
Advanced

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

Re: Implementing a Jacobi iterative method for Ax=b


From: Juan Pablo Carbajal
Subject: Re: Implementing a Jacobi iterative method for Ax=b
Date: Sun, 28 Oct 2012 17:59:06 +0100

On Sun, Oct 28, 2012 at 5:40 PM, Joza <address@hidden> wrote:
> I should add that I am using a zero starting guess, and the convergance test
> is testing the relative residual.
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/Implementing-a-Jacobi-iterative-method-for-Ax-b-tp4645833p4645834.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave

Your code has one error and one unnecessary calculation.

Error:
The step of the Jacobi iteration is
x_new = M\(b - N*x_old);

Unncesessary calculations
M is a diagonal matrix, therefore the inverse is just the inverse of
each diagonal element (take care of zero elements!). Improve the speed
of you code as follows

M = diag(A);

do not build the matrix, just keep the vector

x_new = (b - N*x_old)./M;

The method is not always convergent. Check that the input matrix
guarantees convergence for your tests. For real life usage, limit the
maximum numbe rof interations. When aborting because of max number of
iteration provde a warning and return enough information for the user
to take a decision.
http://en.wikipedia.org/wiki/Jacobi_method#Convergence

Hope that helps


reply via email to

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