diff --git a/README.md b/README.md new file mode 100644 index 0000000..9d333e6 --- /dev/null +++ b/README.md @@ -0,0 +1,98 @@ +# Calculator for Matrix and Algebra + +This is Text-based user interface program that use to solve matrix and algebra problems. + +## Table of Content +- [Calculator for Matrix and Algebra](#calculator-for-matrix-and-algebra) + - [Table of Content](#table-of-content) + - [Overview](#overview) + - [Features](#features) + - [Requirement](#requirement) + - [Program design](#program-design) + - [Code structure](#code-structure) + - [Install and Usage](#install-and-usage) + - [Guide/Documentation](#guidedocumentation) + - [Polynomial](#polynomial) + - [Contributing](#contributing) + + +## Overview + +... + +## Features + +**Calculator for Matrix and Algebra** provide the following function. + +- Ability to solve for basic quadratic, cubic and quartic function. +- Calculate operations of Polynomial function e.g. +/-/*/รท/^. +- Calculate operations of Matrix e.g. Inverse/Tranpose/Basic Operation/Determinant. +- Evaluate the expression(No Variable) that has complex parentheses. +- Some basic algebra operation. e.g. Find reduce form of Fraction etc. + +## Requirement +This program has been created in **Python 3.10.5** and has the following built-in module. +- [ast](https://docs.python.org/3/library/ast.html) : Abstract Syntax Trees +- [math](https://docs.python.org/3/library/math.html) + +## Program design + +... + +## Code structure + +... + +## Install and Usage + +Clone this repository and run the **main.py** + +```` +$ git clone https://github.com/Sosokker/Algebraic-Solving-Tool +```` + +## Guide/Documentation + +After the running of the **main.py**. You can type the command and input into the terminal that look like this. +```` +[1] <- This is line-count. +```` +There are two types of command, input style.\ +*No need expression command* and *Need expression command.* + +>      ***Command*** +      ***or*** +      ***Command[expression]*** + +Whitespace and Case are not matter. Command is same as command. + +For example. +````py +[1] history +# RESULT OF THE INPUT COMMAND +[2] det[[1,2],[3,4]] +# RESULT OF THE INPUT COMMAND +```` +Every command you put in and result of it will be save in **history.json** file. + +### Polynomial +    Polynomial in this class is store in form of array. This are the following command. +- Polynomial[expression] +-> expression str or list + + - This Command use to print all property of the polynomial that user input. + + ```` + [1] polynomial[x^2+2x+1] + + ```` + + +## Contributing + +Pull requests are always welcome and that would be a honor. This first Python project I've dones. I practice using OOP and using github in this work so many parts of code look a bit messy. ๐Ÿ™ˆ + +Thank you so much. + + + diff --git a/nessesary/matrix.py b/nessesary/matrix.py index d2b4736..05eafe0 100644 --- a/nessesary/matrix.py +++ b/nessesary/matrix.py @@ -46,7 +46,7 @@ class Matrix: self.array[row_index][column_index] -= other.array[row_index][column_index] return self - def __mul__(self, other): + def __mul__(self, other: "int | float"): """ Multiply matrix up and those matrix need same dimesional. >>> m1 = Matrix([[1, 2], [3, 4]]) @@ -141,8 +141,30 @@ class Matrix: return new_matrix def inverse(self): + """ + Find Inverse Matrix. + >>> m1 = Matrix([[4, 3],[3, 2]]) + >>> m1.inverse().array + [[-2.0, 3.0], [3.0, -4.0]] + >>> m1 = Matrix([[3, 0, 2],[2, 0, -2],[0, 1, 1]]) + >>> m1.inverse().array + [[0.2, 0.2, 0.0],[-0.2, 0.3, 1.0],[0.2, -0.3, 0.0]] + """ det = self.determinant() - pass + if det==0: + raise ValueError(f"Can't Find Inverse of this Matrix") + + if len(self.array) == 2 and len(self.array[0]) == 2: + return Matrix([[self.array[1][1], -self.array[0][1]], [-self.array[1][0], self.array[0][0]]]) * (1/det) + + temp = self.copy_matrix() + for row in range(self.row): + for col in range(self.column): + minor = lambda i, j : [row[:j] + row[j+1:] for row in (temp.array[:i]+temp.array[i+1:])] + minor_det = Matrix(minor(col, row)).determinant() + temp.array[row][col] = minor_det * (-1)**(row+col+2) + temp = temp.tranpose() + return temp * (1/det) def __str__(self): return f'Matrix({self.array})'