Sci Lab
Sci Lab
2018-103503
Mambuay, Raslany (Gauss-Siedel Method)
2018-107868
Onday, Mark James (Gauss-Siedel Method)
2018-102425
Pagatpatan, Ma Fernanda (Jacobi Method)
2018-102246
Sto. Tomas, Shaira (Jacobi Method)
1|Page
ABSTRACT
In numerical methods and analysis, two of the iterative methods used to
approximate a solution of a system of linear equation is by Jacobi Method and Gauss-
Siedel Method. A solution is an assigned of values to the variables so that all the equations
will be simultaneously satisfied. Gauss-Siedel method, also known as successive
displacement method is an improved Jacobi method where Gauss-Seidel is named after
Carl Friedrich Gauss and Philipp Ludwig von Seidel. For Jacobi method, it is known named
after Carl Gustav Jacob Jacobi. Furthermore, this paper gives the Scilab code to solve a
linear system of equations numerically using Gauss-Siedel and Jacobi Method.
INTRODUCTION
Scilab
Scilab is a free software which we could define as an interpreted language. It is a
high-level, numerically oriented programming language that can be used to create 2D
and 3D plots as well as matrices. The package Scilab provides an environment in which
we can learn to program and execute our numerical methods, namely Jacobi Method
and Gauss-Siedel Method.
Moreover, this program will solve a system of linear of equation by assuming initial
guesses as zero. As convergence was satisfied, solutions of the equations will show and
displays an error note when divergent. This will be further discussed as we go on to this
paper.
2|Page
SOLUTIONS (Source: atozmath.com)
Jacobi Method
3|Page
Gauss-Seidel Method
4|Page
FUNCTIONS (Source: help.scilab.org)
The Scilab functions and commands used are provided in a table below for
further understanding of how it works and used in the program of Jacobi and Gauss-
Siedel Method.
FUNCTION DESCRIPTION
5|Page
PROGRAM FLOWCHART
Flowchart is a graphical representation of an algorithm which is often used by
programmers as a program-planning tool to solve a problem. Below are the Program
Flowcharts and Narratives of Jacobi and Gauss-Siedel Method that will help us to
understand more about the Scilab program made. Also, basic symbols used in the
flowchart will be discussed for further clarity.
Represents as arithmetic
instructions such as adding,
Processing subtracting, etc. are
indicated by action or
process.
Represents a decision
point. Decision based
Decision operations such as yes/no
question or true/false.
6|Page
Jacobi Method
START
Input: n=No. of
equations, tol=No.
of tolerance,
m=No. of iteration
NO
end
while k<=m, error=0
YES
Define: s=(s+A(I,n+1))/A(I,i)
NO YES
If abs(s)>error,
X2(i)=x1(i)+s
error=abs(s)
YES
Display
“Converged” If error<tol
NO
7|Page
Narrative
To begin the algorithm of Jacobi Method, we define first the variables: A, x1, x2,
and k. A=zeros(n, n+1) makes the matrix of A as zeros for n and n+1. As the new n and
n+1 was obtained, the previous n and n+1 will be set to zero or as satisfied by a while or
for loop. x1=zeros(n) and x2=zeros(n) are zero values of the first and second solution with
respect to n. The k=1 is value set as beginning of the iteration and as an interval too. After
defining the variables, the user will be asked for the n: Number of equations, tol: Number
of tolerance, and m: Number of iteration. To complete, the matrix A now should be
defined as a matrix of system of linear of equation. From the scinotes, it is suggested to
put the coefficient for each of the variables and separate each coefficient by a key
space and separate each row by a semi-colon, enclosed by a bracket symbol. Since this
is a Jacobi Method, the program is set to have initial guesses as x1[0 0 0].
Continuing, the program now will read the matrix and start to program: k<=m and
error=0. The program reads the while loop and stops executing as it finds: error=0. When
k<=m was satisfied it will continue as a for loop. The for i=1:n is a function that defines i in
a for loop which will make a matrix of i from 1 to n (Number of equations) only. This also
applies for j=1:n but in a different variable. Proceeding, a new variable is programmed
as s=s-A(I,j)*x1(j). Here, s=0 and A is the matrix of the defined variables i and j enclosed in
a for loop times the variable x1(j) as x1 is defined as zeros of matrix A. After that, the
obtained s will be used for a new predefined function: s=(s+A(i,n+1))/A(i,i), and will be
the new value of s. Going on, the program now reads error in an if statement: if
abs(s)>error and error=abs(s). Satisfying these will again yield to a decision as: if error<=tol.
Again, satisfying that will make another predefined values of: k=k+1, for i=1:n, and
x1(i)=x2(i). Variable k will be the value for a continuous iteration, i are the values inside
the matrix from 1 to n (Number of equations), and x1(i)=x2(i) for values of our solutions.
Upon meeting these criteria, the program now will print for the solutions of the system of
linear of equations shown at the bottom left of the console.
8|Page
Gauss-Siedel Method
Flowchart 1.2: The Gauss-Siedel Method Flowchart
START
NO
end while k<=m
YES
Define:
x1n=(A(1,4)-x2*(A(1,2))-x3*A(1,3)) / A(1,1)
x2n=(A(2,4)-x1n*(A(2,1))-x3*A(2,3)) / A(2,2)
x3n=(A(3,4)-x1n*(A(3,1))-x2n*A(3,2)) / A(3,3)
YES
[1] if abs(x1n-x1>tol [1] x1=x1n
[2] if abs(x2n-x2)>tol [2] x2=x2n
[3] if abs(x3n-x3)>tol [3] x3=x3n
NO
YES
[1] else if abs(x1n-x1)<=tol
[2] else if abs(x2n-x2)<=tol break
[3] else if abs(x3n-x3)<=tol
NO
end
STOP
9|Page
Narrative
In system flowchart, we used our Gauss-Seidel Program method to find the values
of x1, x2, x3, with the equations:
[1] 27x1+6x2-x3=85
[2] 6x1+15x2+x3=72
[3] x1+x2+54x3=110
In order to solve this, our program is designed to transfer the given equations into:
[1] x1=(A(1,4)-x2*(A(1,2))-x3*A(1,3)) / A(1,1)
[2] x2=(A(2,4)-x1*(A(2,1))-x3*A(2,3)) /A(2,2)
[3] x3=(A(3,4)-x1*(A(3,1))-x2*A(3,2)) / A(3,3)
After doing so, the program will ask for n: Number of equations, tol: Number of
tolerance and m: Desired number of Iterations. It is suggested to put the coefficient
values of each variable in the matrix A at the scinotes and separate each coefficient by
a key space and separate each row by a semi-colon, enclosed by a bracket symbol.
Since this is a Gauss-Siedel Method, the initial guesses will be the following: x1=0, x2=0,
and x3=0.
Continuing, the program now will read: k<=m in a while loop and stops executing
as soon as it met the functions of each of the defined variables: x1n, x2n, and x3n; these
variables are discussed earlier and has different formulas for each of them. After that, an
if then else if statement will be used to proceed. First, the program will read if statements
of: if abs(x1n-x1)>tol, if abs(x2n-x2)>tol, and if abs(x3n-x3)>tol, and satisfying these will
yield to another defining functions of: x1=x1n, x2=x2n, and x3=x3n. If not satisfied, it will
come up to an else if statement of the following: else if abs(x1n-x1)<=tol, else if abs(x2n-
x2)<=tol, and else if abs(x3n-x3)<=tol and will initialize a break command, but will
command an end if not.
Under that if then else if statement, we again initialize k to be k=k+1 for continuous
iteration and will finally print the solutions of the given system of linear of equations.
Moreover, if the conditions abs(xn-x)>tol is met, the program will continue to solve,
however if it is not, the program will stop. This means that the equations did not converge.
To fix this problem, the equations must be re-arranged or must increase m: number of
iterations.
10 | P a g e
SAMPLE OUTPUT
Below are the sample outputs of the Jacobi and Gauss-Siedel Method programs.
Each of the output will be briefly describe for better understanding and clarity.
Jacobi Method
Figure 1.1 shows the program code of the Jacobi Method which is based on the
program flowchart given earlier (see Flowchart 1.1, page ). This program will solve for
the solutions of a system of linear of equations by Jacobi Method.
11 | P a g e
Figure 1. 2: Converged Jacobi Method in Console
Figure 1.2 shows executed Jacobi Method program in a console. As you can see,
the input values are: n=3, tol=0.001, and m=9. The given input values converged into a
solution of: x1=2.426, x2=3.573, and x3=1.926. This is true as the solution of Jacobi Method
also converges to ninth iteration (see page 3).
The above figure shows input values of: n=3, tol=0.001, and m=5. The Jacobi
Method Program will not converge into a solution if and only if: [1] The matrix A in the
scinotes is not diagonally dominant or [2] The input number of iterations m is not sufficient
to converge into a solution. In this case, the executed Jacobi Method program diverges
because we only put 5 iterations. This system of linear of equation by Jacobi Method will
only converge at ninth iteration.
12 | P a g e
Gauss-Siedel Method
This figure shows the scilab code of the Gauss-Siedel Method. It is based on
the program flowchart given earlier (see Flowchart 1.2, page 9). This program will solve
for the solutions of our system of linear equations given at the matrix A of this program, at
line 10 of scinotes by Gauss-Siedel Method.
13 | P a g e
Figure 1.5: Converged Gauss-Siedel Method in Console
The above figure shows an executed scilab program of Gauss-Siedel Method. The
input values are the following: n=3, tol=0.0001, and m=5. As we can see, without
indicating converging or diverging note, the program converges at: x1=2.425, x2=3.573,
and x3=1.926. To know the convergence, see row 4 and the note “Solution vector after
5 iterations”, both have the same values of x1, x2, and x3. To sum up, the fourth row is the
fourth iteration and the solutions at the bottom part are just the same as the fifth row or
fifth iteration of the method. Also, this is true as the solution of this method is also the same
as the table of solutions (see page 4). To add up, the input tol should always be 0.0001
because the program we made is limited only at this given. That input will give the solution
more accurate but inputting other tol like 0.001 will also give a solution but not as
accurate as it is.
Figure 1.6: Diverged Gauss-Siedel Method in Console
This figure shows divergence of the method with an input value of: m=3, see that
the bottom part indicating “Solution vector after 5 iterations is” shows solution at fifth
14 | P a g e
iteration even if we set the iteration number to 3. This indicates that the solutions of this
method will converge only at fifth iteration. We suggest to increase the number of
iteration m. To clarify this more, see the next figure (Figure 1.7).
With an input value of 10 at m, the program stops solving at the fifth iteration and
shows the solutions of the Gauss-Siedel Method that converged again at: x1=2.425,
x2=3.573, and x3=1.926. As we said earlier, this program is bound to show only the
solutions as soon as it met convergence. In this given matrix of A, we can conclude that
convergence is found at fifth iteration.
CONCLUSION
In this documentation, we developed a Scilab code of Jacobi and Gauss-Siedel
Method to solve a system of linear equations numerically. The user can easily manipulate
the system and get the solutions by changing the coefficient values at the matrix A found
in the scinotes, it is applicable for both programs. We also notice how fast the
convergence of Gauss-Siedel Method than the Jacobi Method is, it is about twice as fast
than the other. All in all, the making of this program is beneficial to us because we learned
how the two methods works and how it can be applied as a Scilab program to easily
solve a system of linear equation.
15 | P a g e
REFERENCES
[1] Yang, K. (2018). Gauss-Siedel method: An overview. Science Direct. Retrieved from
https://www.sciencedirect.com/topics/engineering/gauss-seidel-method
[2] Wikipedia contributors. (2020, October 27). Scilab. In Wikipedia, The Free
Encyclopedia. Retrieved 09:20, November 11, 2020, from
https://en.wikipedia.org/w/index.php?title=Scilab&oldid=985699232
[3] Riyasdeen, S., Abbas, S., and Lenin, T. (2019). Illustration of gauss-siedel method using
matlab. International Journal of Applied Engineering Research, 14, 2234-2237.
[4] Aggarwal, N. (n.d.). An introduction to flowcharts. Geeks for Geeks. Retrieved from
https://www.geeksforgeeks.org/an-introduction-to-flowcharts/amp
16 | P a g e