1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help with Matlab

  1. Aug 6, 2008 #1
    Help with Matlab!!!

    Hi,
    I've just started learning how to use the Matlab and came across this question in the textbook:
    Consider the following system of equations:
    [-1 2 4 1 0]
    [ 5 4 0 0 0]
    [ 0 6 1 0 4] x =
    [ 0 -1 0 -1 4]
    [ 1 0 -2 -5 1]

    [ 1 ]
    [ 1 ]
    [ 1 ]
    [ 1 ]
    [ 1 ]


    Write a Matlab script file, using the Matlab function gauss seidel that:
    (a) Sets up the matrix and the vector in the system of equations
    (b) Applies 5 iterations of the gauss seidel method using x(0)=[0,0,0,0,0]T

    Now I know how to part (b) but can't seem to get my head around part (a). I have attached a copy of the gauss seidel function I wrote. I know for part (b) I have to put in the values of the inputs: A,b,y,N and then simply execute the function. I really don't know how to solve part (a). Help Please!!!:cry:

    Edit to say: I honestly don't really understand part (a) of the question. If they are simply asking me to write up the matrix and the vector to calculate the x vector then I know how to do that but I don't know if the question is asking me to actually set it up as x1+x2+x3+...=some no.
    If so, do I simply create an M-file like the one below???
    A=[-1 2 4 1 0;5 4 0 0 0;0 6 1 0 4;0 -1 0 -1 4;1 0 -2 -5 1]
    b=[1;1;1;1;1]
    x = A\b

    Gauss Seidel function:
    function x = gs (A,b,y,N)

    n = length(y);

    x = y;

    for k=1:N
    for i=1:n
    sum = b(i);
    for j=1:i-1
    sum = sum - A(i,j)*x(j);
    end
    for j = i+1:n
    sum = sum - A(i,j)*y(j);
    end
    x(i) = sum/A(i,i);
    end
    y = x';
    end
     
    Last edited: Aug 6, 2008
  2. jcsd
  3. Aug 12, 2008 #2

    MATLABdude

    User Avatar
    Science Advisor

    Re: Help with Matlab!!!

    What an opportune moment to have joined!

    From my reading of part a, your interpretation is correct. Make a matrix of coefficients (what you have as A) and a vector of equation solutions (what you have as b). This allows you to use it with part b. Sometimes questions really are as easy as you think they are. ;-)
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Help with Matlab
  1. MATLAB help (Replies: 9)

  2. MATLAB help (Replies: 2)

  3. MATLAB help (Replies: 0)

  4. MATLAB help (Replies: 7)

  5. Matlab help (Replies: 6)

Loading...