Results 1 to 1 of 1

Math Help - Gauss-Seidel method in Matlab

  1. #1
    Member
    Joined
    Dec 2009
    Posts
    225

    Gauss-Seidel method in Matlab



    Attempt:

    This is my code so far:


    Code:
    clear all
    clc
    clf
    function x=GaussSeidel(A,b,y,N)
    n = length(y);
    for k = 1:N
        for i=1:n
            s=b(i);
            for j =1:i-1
                s=s-A(i,j)*y(j);
            end
            for j = i+1:n
                s=s-A(i,j)*y(j);
            end
            x(i)=s/A(i,i);
            x(i)=x(k);
        end
        y = x'
    end
    However I am getting the following error:
    Code:
    Error: File: Untitled.m Line: 4 Column: 1
    Function definitions are not permitted in this context.
    Why am I getting this error? What do I need to do?

    And my inputs are:

    Code:
    A=[-5 0 2 0 -1 ;
        0 9 0 3 0 ; 
        2 0 5 0 2 ;
        0 -2 0 4 0 ;
        -1 0 7 0 7]
    b = [8;4;-8;-4;0]
    x0=[8;4;-8;-4;0]
    For N, how do I know many iterates N are necessary for this problem?

    Any help with the code is greatly appreciated.
    Last edited by demode; March 15th 2012 at 02:47 PM.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Gauss-Seidel iteration in Matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: September 21st 2010, 10:37 PM
  2. Gauss-Seidel problem
    Posted in the Advanced Applied Math Forum
    Replies: 0
    Last Post: October 29th 2009, 01:19 PM
  3. Guaranteeing convergence for Jacobi and Gauss-Seidel.
    Posted in the Advanced Algebra Forum
    Replies: 0
    Last Post: September 11th 2009, 09:15 AM
  4. Problem with Matrix and Gauss-Seidel (Maple)
    Posted in the Advanced Algebra Forum
    Replies: 0
    Last Post: January 14th 2009, 02:43 PM
  5. MAPLE - Jacobi & Gauss-Seidel Iteration
    Posted in the Math Software Forum
    Replies: 0
    Last Post: December 12th 2008, 07:07 AM

Search Tags


/mathhelpforum @mathhelpforum