Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    Hi,

    I have to write a Matlab code for the Gauss-Seidel method to solve a set of n linear equations in n unknowns in which the user will input the initial guesses and the maximum error. However, I am relatively new to this and this is really getting confusing, can someone please help to out. This is the code which I have written so far but obviously it doesn't work, which is in a script file:

    display('enter your matrix in the form of AX=B')
    A=input('A=')
    B=input('B=')
    n=size(A,1);
    display('write your starting guesses in matrix form e.g. [3 -9 6]')
    x(1:n)=input('starting guesses=')
    Emax=input('maximum error=')
    %Emax is the maximum error that you desire
    nmax=input('maximum number of iterations=');
    %imax is the maximum number of iterations that you desire

    n=o
    while (error>Emax && n<nmax)
    sum=0
    for k=1:n
    for i=k:n
    for j=k:n
    sum=sum+A(i,j)*x(j)
    x(i)=(1/(A(i,i)))*(B(i)-sum)
    end
    end
    end
    error=abs((x(k)-x(i))/x(k))
    n=n+1
    x(i)-x(k);
    end

    Many thanks
 
 
 
Poll
Do you agree with the PM's proposal to cut tuition fees for some courses?
Useful resources

Make your revision easier

Maths

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

Equations

How to use LaTex

Writing equations the easy way

Student revising

Study habits of A* students

Top tips from students who have already aced their exams

Study Planner

Create your own Study Planner

Never miss a deadline again

Polling station sign

Thinking about a maths degree?

Chat with other maths applicants

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.