Git Product home page Git Product logo

matrix-processor's Introduction

๐Ÿงฎ Matrix Processor

Recommended for anyone studying Matrices & Determinants during Online Classes ๐Ÿ˜Ž

Run on Repl.it

This program can accomplish tasks such as addition, subtraction and multiplication of matrices along with finding determinants and inverses of a matrix. May be pretty helplful in online classes to calculate on the fly. It can calculate ~85 % of NCERT questions. Trust me, I myself have used this in my math class and the teacher was really impressed.

MVP: Finding Inverse

Usage

  • Cut / copy code source from processor.py and paste to run via your favourite editor.
  • repl.it button

Demo

  1. Matrix Multiplication
Numeric Matrix Processor

1. Add Matrices
2. Multiply matrix by a constant
3. Multiply matrices
4. Transpose matrix
5. Calculate a determinant
6. Inverse matrix
0. Exit
Your choice: > 3
Enter size of first matrix: > 3 3
Enter first matrix: 
> 1 7 7
> 6 6 4
> 4 2 1
Enter size of second matrix: > 3 3
Enter second matrix: 
> 3 2 4
> 5 5 9
> 8 0 10
The result is: 
94 37 137
80 42 118
30 18 44
  1. Finding inverse of a really complex matrix to show how cool this is.
    • Answer is correct. I checked on Wolfram-Alpha :-)
Numeric Matrix Processor

1. Add Matrices
2. Multiply matrix by a constant
3. Multiply matrices
4. Transpose matrix
5. Calculate a determinant
6. Inverse matrix
0. Exit
Your choice: > 6
Enter matrix size: > 4 4
Enter matrix: 
> 2.65 3.54 3.88 8.99
> 3.12 5.45 7.77 5.56
> 5.31 2.23 2.33 9.81
> 1.67 1.67 1.01 9.99
The result is: 
0.397 -0.215 0.277  -0.509
5.197 -2.07  -0.389 -3.143
-3.38  1.502  0.16   2.048
-0.593 0.23   0.003  0.503

Contributing

The code may (most certainly) have bugs. Please feel free to open up an issue describing how I messed up (in a polite way please.)

  • soumitradev helped with initial testing and maintaining the repo.
  • bangyen

ToDo

  • Add comments
  • Beautify output
  • Better error handling for make()
  • Look into operations on 2x2 matrices.

matrix-processor's People

Contributors

bangyen avatar mdvsh avatar soumitradev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

soumitradev

matrix-processor's Issues

smol bugs

smol bugs here and there
will fix after exams ๐Ÿ˜ž

make() needs better error handling

I don't know if you want to handle all errors, but make() needs better error handling when the input is invalid.

the row = input().split(maxsplit=self.C) and the code after the line gives a string to float conversion error when the user inputs more numbers than the size.

Maybe we can check if the line has the correct number of numbers and then ask the user to enter a valid row if the input is invalid?

Performance improvements for alternating signs

When calculating determinant and inverse, we could half the time needed to alternate the signs.

import time
a = time.time()
for i in range(1000):
    for j in range(10000):
        k = (-1) ** (i + j)
b = time.time()
print(b - a)

c = time.time()
for i in range(1000):
    for j in range(10000):
        k = -1 if ((i + j) % 2) else 1
d = time.time()
print(d - c)

When I run the above script, the usual line that alternates the signs of the result takes around 5 seconds, while the ternary result takes around 2.5 seconds. This could speed some large calculations up.

I'll implement this in my next PR.

Determinant of column vector gives first element in matrix

Title says it all.

In processor.py,

    def determinant(self):
        if len(self.matrix[0]) == 1:
            return self.matrix[0][0]
        elif (self.R == self.C) and (self.R != 1):
            M = self.matrix
            return self.det_recur(M)
        else:
            return "The operation cannot be performed."

If we run

A = Matrix(4, 1)
A.matrix = [[1], [2], [3], [4]]
print(A.determinant())

The code outputs 1.

I'll fix this in my next PR.

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.