Hey there! Sign in to join this conversationNew here? Join for free
 You are Here: Home >< Maths

Gauss-Seidel Matlab Code watch

1. 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

Reply
Submit reply
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: April 3, 2013
Today on TSR

Struggling to get going with your revision?

Get going with the all day revision thread

Uni strikes! How do they affect you?

Discussions on TSR

• Latest
Poll
Useful resources

Make your revision easier

Maths Forum posting guidelines

Not sure where to post? Read the updated guidelines here

How to use LaTex

Writing equations the easy way

Study habits of A* students

Top tips from students who have already aced their exams

Create your own Study Planner

Never miss a deadline again

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
Discussions on TSR

• Latest

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.