implementation of jacobi method