/gauss-seidel-method

An command-line app to solve systems of equations (3x3 only) using the iterative Gauss-Seidel Method, with user-specified decimal accuracy.

Primary LanguageC#

I made this originally as a one-off personal project for my CPE2237 Numerical Methods subject somewhere around January 2022, as a simple calculator of this kind and originally only up to 3 decimal places accurate. Only recently I cleaned the code when uploading this.

What is the Gauss-Seidel Method

It is a method used in solving systems of equations iteratively, rather than using the usual Gauss-Jordan elimination method. Since it is iterative, it is fast even to the largest matrices, at the cost of precision because the $x$ values are an approximation.

Gauss-Seidel and Gauss-Jacobi are very similar in execution, but the feature that sets them both apart is that the former's $x$ values are modified as soon as the previous value is evaluated (i.e. after evaluating $x_1$, the value is used as part of calculating $x_2$ and so on), leading to faster convergence. What's common for them however, is that you need a (strictly) diagonally dominant matrix in order for it to work — or else you'll be stuck in an infinite loop.

For a 3x3 augmented matrix, where the coefficients ($a$'s) of the 3x3 matrix are on the left side and the resultant vector $B$ (represented by $b$'s) on the right side,



the formula is:

lagrida_latex_editor

Where:

  • $a_{ij}$ = Coefficients ($a_{11}, a_{12},$ etc.).
  • $b_i$ = Resultant vector's ($B$) coefficients ($b_1, b_2,$ etc.).
  • $k$ - Iteration №.
    • The 0th iteration of each $x$'s are usually set to 0 or an arbitrary value.

The loop stops once the previous iteration's ($k-1$) $x$ values is the same as the newly evaluated current iteration's ($k$) $x$ values.

A 3x3 matrix is said to be (strictly) diagonally dominant if it satisfies all three of these conditions:

lagrida_latex_editor (1)


How to install

  1. Make sure you have .NET Core 3.1 or higher (since it uses C# 8.0).
  2. Make sure you also have ConsoleTables. You can download it from the NuGet package manager.
  3. Click the latest version on the Releases section and download the source code. Alternatively, click the green code button and download as a ZIP (or you can clone it).
  4. Open your favorite code editor of your choice (Visual Studio is more recommended than VS Code).
  5. Open the solution file and then run (Visual Studio) or open the folder of the project and then run the Program.cs file (VS Code and other code editors).
    • You can also run it from the terminal but make sure you use Roslyn as the compiler.
  6. Enjoy!