Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Version 1.3.1 - Bêta
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow15510 committed Jul 13, 2020
1 parent 22a0967 commit bae4dc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Vecmat is a librairie of vectorial and matricial manipulations. This librairie is oriented-object, so you can use `Vector` and `Matrix` like `list` or `str` objects. This librairie was made by Charlotte THOMAS and Sha-Chan~.

Version 1.3 released on 11 of July.
Version 1.3.1 - Bêta released on 12 of July.

### Licence

Expand Down Expand Up @@ -51,7 +51,6 @@ For initialise a matrix follow this scheme `M = Matrix([1, 2], [3, 4])`. You can
#### Handlings on the matrix itself

- The matrices are printable and return a string representation of the column and rows.
- `get_coef(i, j)` : Returns the i, j coefficient of the matrix. (Please take care, as well as for list, the index start at 0.)
- `get_dim()` : Returns the dimension of the matrix. The results is a tuple : `(row, column)`.
- `switch_row(row_1, row_2)` : Reverses the two rows.
- `switch_column(column_1, column_2)` : Reverses the two columns.
Expand Down
26 changes: 13 additions & 13 deletions vecmat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# --------------------------------------------------
# Vecmat (Version 1.3)
# Vecmat (Version 1.3.1 - Bêta)
# by Charlotte THOMAS and Sha-Chan~
# last version released on the 11 of July.
# last version released on the 12 of July.
#
# code provided with licence (CC BY-NC-SA 4.0)
# for more information about licence :
Expand Down Expand Up @@ -44,12 +44,15 @@ def __truediv__(self, x):
def __str__(self):
return str(tuple(self.coord))

__radd__ = __add__
__rmul__ = __mul__

def __abs__(self):
return sqrt(sum(list(map(lambda i: i**2, self.coord))))

def __getitem__(self, index):
return self.coord[index]

__radd__ = __add__
__rmul__ = __mul__

def unitV(self):
a = abs(self)
return Vector(*map(lambda x: x/a, self.coord))
Expand All @@ -69,11 +72,11 @@ def colinear(self, vec: "Vector"):
def angle(self, vec: "Vector"):
return round(degrees(acos(self.dotP(vec) / (abs(self)*abs(vec)))), 2)


class Matrix:
def __init__(self, *row):
self.content = [i for i in row]


def __add__(self, matrix: "Matrix"):
if self.get_dim() != matrix.get_dim():
raise ArithmeticError("The dimensions are incompatible")
Expand Down Expand Up @@ -103,11 +106,11 @@ def __truediv__(self, x):
def __str__(self):
return "\n".join(map(str, self.content))

def __getitem__(self, index):
return self.content[index]

__radd__ = __add__
__rmul__ = __mul__

def get_coef(self, i, j):
return self.content[i][j]

def get_dim(self):
return len(self.content), len(self.content[0])
Expand All @@ -130,9 +133,6 @@ def calc_det(mat: "Matrix"):
def gauss_jordan_determinant(self):
pass

def swapping_rows(self, r1: int, r2: int):
self.content[r1], self.content[r2] = self.content[r2], self.content[r1]

def add_multiple_of_row(self, row1: int, row2: int, multiple: float):
#Multiply row1 by multiple and adding that to row2
self.content[row2] = list(map(lambda x,y: x+y, map(lambda x: x*multiple, self.content[row1]), self.content[row2]))
Expand All @@ -150,7 +150,7 @@ def inverse(self):
return self.comat().transpose() * (1/self.det())

def switch_row(self, row_1: "int", row_2: "int"):
for j in range(len(self.content[0])): self.content[row_1][j], self.content[row_2][j] = self.content[row_2][j], self.content[row_1][j]
self.content[row_1], self.content[row_2] = self.content[row_2], self.content[row_1]

def switch_column(self, column_1: "int", column_2: "int"):
for i in range(len(self.content)): self.content[i][column_1], self.content[i][column_2] = self.content[i][column_2], self.content[i][column_1]
Expand Down

0 comments on commit bae4dc1

Please sign in to comment.