Skip to content

A medium-complex Java program, that is designed and built for the purpose of Solving a System of Linear Equations.

Notifications You must be signed in to change notification settings

GaygysyzMyradov/linear-equations-calculator

Repository files navigation

linear-equations-calculator

A medium-complex Java program, that is designed and built for the purpose of Solving a System of Linear Equations.

Code and Implementation Description

The way this program works is as followed:

Suppose that you are given a linear equation and you are required to find all the unknown x values as follow:

image

A system of linear equations with m equations and n unknowns if and only if n=m is expressed as follows,

image

The above system is represented in matrix form as Ax= b, as follows,

image

To find the unknown variables x the following steps are being accomplished:

  1. Convert the linear equation to the matrix format:

image

The system takes TWO dimensional array Matrix A and a single dimensional array Vector X, and another single dimensional array Vector b

  1. The system will then check if the matrix A is diagonally dominant and Make the matrix diagonally dominant, if it is not.

Description: A square matrix A is said to be diagonally dominant if the absolute value of its diagonal element in each row is greater than the sum of the absolute value of all other elements in the same row.

image

Hint: The matrix A is not diagonally-dominant but becomes diagonally-dominant by exchanging the rows. In the example, we bring the row 4 to the first row and shifting all the other rows downward. Note that the vector b is also changed according to their corresponding rows in the matrix A. Therefore, the linear equation in the form of matrix will look like the followings:

image

  1. Find the x for each row. I have implemented the loop at this step and iteratively calculated the unknown variable x until the Greatest Absolute Value of each unknown x (Error) subtracted by the Greatest Absolute Value from the previous step is smaller than the epsilon (0.005. The initial vector x (at iteration k=0) is given as x-[0,0,0,0].

The definition of notations are as follows:

image

The variable X𝑟 (x for each row) at each iteration k, is written in terms of other variables as follows:

image

Where i and j is the index of row and column at each iteration.

The initial vector x is given as x= [0, 0, 0, 0]=> 𝑥1 = 0, 𝑥2 = 0, 𝑥3 = 0, 𝑥4 = 0.

Formula for calculating the unknown x:

image

General formula:

image

Example:

When k=0:

image

The error is greater than the tolerance. Therefore, the iterations continue with k=1. Continuing the iteration produces the results as shown in table below.

image

The pseudocode of the algorithm is as follows:

image


Build Instructions

  1. Make sure you have successfully installed the Latest Version of Java JDK. You may download it here.
  2. Download the Repo source code files.
  3. If you have completed the above steps correctly, then you should be able to run it successfully.

[NOTE]

All the comments and the explaination of the Methods and the Classes has been added to the source code.


Demo

  • Getting Dimensions (Success):

image

  • Getting Dimensions (Unsuccessful):

image

  • Getting Elements of Matrix, A and Vector B:

image

  • Checking Diagonal Dominance (Diagonally Dominant):

image

  • Checking Diagonal Dominance (Not Diagonally Dominant & Dominance is Possible):

image

  • Checking Diagonal Dominance (Not Diagonally Dominant & Dominance is Impossible):

image


If you have suggestions, please feel free to contribute, looking forward to practice and learn more. Thanks!

About

A medium-complex Java program, that is designed and built for the purpose of Solving a System of Linear Equations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages