Giter Site home page Giter Site logo

multiequationsolver's Introduction

Multi Equation Solver

In this we use the Gauss Jordan method of solving a matrix to determine the exact solution of a set of multi variable equations, provided that the system of equations aren't inconsistent.

Gauss Jordan

Row Echelon Form & The Reduced Row Echelon Form

In this we make the reduced row echelon form of the matrix.
The properties of a Reduced Row Echelon Matrix are as follows :

  • If a row doesn't consist of zeroes only, the first non zero number must be 1, and it's called the leading one.
  • If a row only consists of zeroes, it must be moved to the bottom.
  • For each non zero row, the leading one must be to the right, and below the other leading one's.
  • In a column with a leading one, the other elements must be 0.

The only difference between the row echelon and a reduced row echelon form is the 4th point of the above mentioned properties.

Why don't we consider any of the rows to be completely filled with zeroes in this project?

In this project however, we don't consider any of the rows to be completely filled with zeroes, as it would mean that the system of equations is inconsistent (since the rank of the matrix would be less than the number of variables).

Rank of a Matrix

The rank of a matrix is the number of non zero rows in the reduced row echelon form of the matrix.

Usage of rank to determine whether the system of equations is consistent or not

If we consider the equation matrix to be A, and the augmented matrix to be B, the form of the equation is AX=B. Also, we consider n to be the number of variables in the system of equations.

  • If Rank(A) = Rank(A|B) < n -> Infinite Solutions
  • If Rank(A) = Rank(A|B) = n -> Unique Solution
  • If Rank(A) โ‰  Rank(A|B) -> No Solution

Cramers Rule Method for inconsistent systems

If the system of equations is inconsistent, we can use the Cramers Rule method to determine the solution of the system of equations.

It states that if the determinant of the coefficient matrix is zero, then the system of equations is inconsistent.

Usage

In this project, we use Cramers rule to determine if the set of equations is consistent of not. If it is consistent, we use the Gauss Jordan method to determine the solution of the system of equations.

We could have used just the cramers rule method, but I used the Gauss Jordan method as I just learnt it and wanted to implement it. Also, I heard that it's faster than the Cramers rule method.

How to use

  • The first line of the input is the number of variables or the number of equations. We take this value as 'n'.
  • The next 'n' lines are the coefficients of the variables in the equations. The last number in each line is the constant.
  • For example, for the equation, 2x + 3y = 5, the input would be 2 3 5.

Example

Input

g++ main.cpp -o main
./main
3
1 2 3 6
4 5 6 15
1 1 1 3

Number of variables : 3
1x + 2y + 3z = 6 : 1 2 3 6
4x + 5y + 6z = 15 : 4 5 6 15
1x + 1y + 1z = 3 : 1 1 1 3

Output

1 0 0 1
0 1 0 1
0 0 1 1

The output is the reduced row echelon form of the augmented matrix.

1x + 0y + 0z = 1 : 1 0 0 1 -> x = 1
0x + 1y + 0z = 1 : 0 1 0 1 -> y = 1
0x + 0y + 1z = 1 : 0 0 1 1 -> z = 1

The solution of the system of equations is x = 1, y = 1, z = 1.

References

multiequationsolver's People

Contributors

darelife avatar

Watchers

 avatar

Forkers

saksham-agarwal

multiequationsolver's Issues

divide by 0 case (the bug was found on 7th Feburary 2024, but i mentioned it in the readme, as i never felt like fixing it)

Just discovered a bug (07-02-2024) for the input

4       
1 1 1 1 4
2 2 1 2 7
5 4 5 4 18
8 9 1 0 18

The output is

------------------
         1          1          1          1          4 
         2          2          1          2          7
         5          4          5          4         18
         8          9          1          0         18
------------------
------------------
         1          1          1          1          4
         0          0         -1          0         -1
         0         -1          0         -1         -2
         0          1         -7         -8        -14
------------------
------------------
         1          1          1          1          4
       nan        nan       -inf        nan       -inf
         0         -1          0         -1         -2
         0          1         -7         -8        -14
------------------
------------------
         1          1          1          1          4
       nan        nan       -inf        nan       -inf 
       nan        nan       -inf        nan       -inf
       nan        nan        inf        nan        inf
------------------
------------------
         1          1          1          1          4
       nan        nan       -inf        nan       -inf
       nan        nan        nan        nan        nan
       nan        nan        inf        nan        inf
------------------
------------------
         1          1          1          1          4
       nan        nan       -inf        nan       -inf 
       nan        nan        nan        nan        nan
       nan        nan        nan        nan        nan
------------------
------------------
         1          1          1          1          4
       nan        nan       -inf        nan       -inf
       nan        nan        nan        nan        nan
       nan        nan        nan        nan        nan
------------------
------------------
         1          1          1          1          4
       nan        nan       -inf        nan       -inf
       nan        nan        nan        nan        nan
       nan        nan        nan        nan        nan
------------------
------------------
       nan        nan        nan        nan        nan
       nan        nan        nan        nan        nan
       nan        nan        nan        nan        nan
       nan        nan        nan        nan        nan 
------------------


### Why did this happen? The reason is this happened is due to the fact that the second row is trying to divide itself by 0, since the second element of the second row is 0. This is a bug in the code. (However, the code is working fine for the other inputs, so I'm not going to fix it. I'm just going to leave it as it is.)

(The bug was identified between these two steps)

------------------
         1          1          1          1          4
         0          0         -1          0         -1
         0         -1          0         -1         -2
         0          1         -7         -8        -14
------------------
------------------
         1          1          1          1          4
       nan        nan       -inf        nan       -inf
         0         -1          0         -1         -2
         0          1         -7         -8        -14
------------------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.