Skip to content

Commit

Permalink
Rewrite parts of Vector and Matrix (TheAlgorithms#5362)
Browse files Browse the repository at this point in the history
* Rewrite parts of Vector and Matrix methods

* Refactor determinant method and add unit tests

Refactor determinant method to create separate minor and cofactor
methods.
Add respective unit tests for new methods.
Rename methods using snake case to follow Python naming conventions.

* Reorganize Vector and Matrix methods

* Update linear_algebra/README.md

Co-authored-by: John Law <[email protected]>

* Fix punctuation and wording

* Apply suggestions from code review

Co-authored-by: John Law <[email protected]>

Co-authored-by: John Law <[email protected]>
  • Loading branch information
tianyizheng02 and poyea authored Oct 27, 2021
1 parent 8285913 commit fe5c711
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 225 deletions.
2 changes: 1 addition & 1 deletion knapsack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The knapsack problem has been studied for more than a century, with early works
## Documentation

This module uses docstrings to enable the use of Python's in-built `help(...)` function.
For instance, try `help(Vector)`, `help(unitBasisVector)`, and `help(CLASSNAME.METHODNAME)`.
For instance, try `help(Vector)`, `help(unit_basis_vector)`, and `help(CLASSNAME.METHODNAME)`.

---

Expand Down
44 changes: 22 additions & 22 deletions linear_algebra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,56 @@ This module contains classes and functions for doing linear algebra.
-
- This class represents a vector of arbitrary size and related operations.

**Overview about the methods:**
**Overview of the methods:**

- constructor(components : list) : init the vector
- set(components : list) : changes the vector components.
- constructor(components) : init the vector
- set(components) : changes the vector components.
- \_\_str\_\_() : toString method
- component(i : int): gets the i-th component (start by 0)
- component(i): gets the i-th component (0-indexed)
- \_\_len\_\_() : gets the size / length of the vector (number of components)
- euclidLength() : returns the eulidean length of the vector.
- euclidean_length() : returns the eulidean length of the vector
- operator + : vector addition
- operator - : vector subtraction
- operator * : scalar multiplication and dot product
- copy() : copies this vector and returns it.
- changeComponent(pos,value) : changes the specified component.
- copy() : copies this vector and returns it
- change_component(pos,value) : changes the specified component

- function zeroVector(dimension)
- function zero_vector(dimension)
- returns a zero vector of 'dimension'
- function unitBasisVector(dimension,pos)
- returns a unit basis vector with a One at index 'pos' (indexing at 0)
- function axpy(scalar,vector1,vector2)
- function unit_basis_vector(dimension, pos)
- returns a unit basis vector with a one at index 'pos' (0-indexed)
- function axpy(scalar, vector1, vector2)
- computes the axpy operation
- function randomVector(N,a,b)
- returns a random vector of size N, with random integer components between 'a' and 'b'.
- function random_vector(N, a, b)
- returns a random vector of size N, with random integer components between 'a' and 'b' inclusive

### class Matrix
-
- This class represents a matrix of arbitrary size and operations on it.

**Overview about the methods:**
**Overview of the methods:**

- \_\_str\_\_() : returns a string representation
- operator * : implements the matrix vector multiplication
implements the matrix-scalar multiplication.
- changeComponent(x,y,value) : changes the specified component.
- component(x,y) : returns the specified component.
- change_component(x, y, value) : changes the specified component.
- component(x, y) : returns the specified component.
- width() : returns the width of the matrix
- height() : returns the height of the matrix
- determinate() : returns the determinate of the matrix if it is square
- determinant() : returns the determinant of the matrix if it is square
- operator + : implements the matrix-addition.
- operator - _ implements the matrix-subtraction
- operator - : implements the matrix-subtraction

- function squareZeroMatrix(N)
- function square_zero_matrix(N)
- returns a square zero-matrix of dimension NxN
- function randomMatrix(W,H,a,b)
- returns a random matrix WxH with integer components between 'a' and 'b'
- function random_matrix(W, H, a, b)
- returns a random matrix WxH with integer components between 'a' and 'b' inclusive
---

## Documentation

This module uses docstrings to enable the use of Python's in-built `help(...)` function.
For instance, try `help(Vector)`, `help(unitBasisVector)`, and `help(CLASSNAME.METHODNAME)`.
For instance, try `help(Vector)`, `help(unit_basis_vector)`, and `help(CLASSNAME.METHODNAME)`.

---

Expand Down
Loading

0 comments on commit fe5c711

Please sign in to comment.