Remove separate directory for gaussian_elimination_pivoting.py (#11445)

* updating DIRECTORY.md

* Remove separate directory for gaussian_elimination_pivoting.py

Delete the directory linear_algebra/src/gaussian_elimination_pivoting/
and move its algorithm file, gaussian_elimination_pivoting.py, into the
parent src/ directory. The gaussian_elimination_pivoting/ directory only
exists because gaussian_elimination_pivoting.py reads an example numpy
array from matrix.txt, but this input file and IO operation is entirely
unnecessary because gaussian_elimination_pivoting.py already has the
exact same array hard-coded into a variable.

* updating DIRECTORY.md

---------

Co-authored-by: tianyizheng02 <tianyizheng02@users.noreply.github.com>
This commit is contained in:
Tianyi Zheng 2024-08-22 09:42:40 -07:00 committed by GitHub
parent 31c424fc86
commit 48418280b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 25 deletions

View File

@ -540,8 +540,7 @@
* [Lu Decomposition](linear_algebra/lu_decomposition.py) * [Lu Decomposition](linear_algebra/lu_decomposition.py)
* Src * Src
* [Conjugate Gradient](linear_algebra/src/conjugate_gradient.py) * [Conjugate Gradient](linear_algebra/src/conjugate_gradient.py)
* Gaussian Elimination Pivoting * [Gaussian Elimination Pivoting](linear_algebra/src/gaussian_elimination_pivoting.py)
* [Gaussian Elimination Pivoting](linear_algebra/src/gaussian_elimination_pivoting/gaussian_elimination_pivoting.py)
* [Lib](linear_algebra/src/lib.py) * [Lib](linear_algebra/src/lib.py)
* [Polynom For Points](linear_algebra/src/polynom_for_points.py) * [Polynom For Points](linear_algebra/src/polynom_for_points.py)
* [Power Iteration](linear_algebra/src/power_iteration.py) * [Power Iteration](linear_algebra/src/power_iteration.py)

View File

@ -1,15 +1,5 @@
import numpy as np import numpy as np
matrix = np.array(
[
[5.0, -5.0, -3.0, 4.0, -11.0],
[1.0, -4.0, 6.0, -4.0, -10.0],
[-2.0, -5.0, 4.0, -5.0, -12.0],
[-3.0, -3.0, 5.0, -5.0, 8.0],
],
dtype=float,
)
def solve_linear_system(matrix: np.ndarray) -> np.ndarray: def solve_linear_system(matrix: np.ndarray) -> np.ndarray:
""" """
@ -87,15 +77,18 @@ def solve_linear_system(matrix: np.ndarray) -> np.ndarray:
if __name__ == "__main__": if __name__ == "__main__":
from doctest import testmod from doctest import testmod
from pathlib import Path
testmod() testmod()
file_path = Path(__file__).parent / "matrix.txt"
try:
matrix = np.loadtxt(file_path)
except FileNotFoundError:
print(f"Error: {file_path} not found. Using default matrix instead.")
# Example usage: example_matrix = np.array(
print(f"Matrix:\n{matrix}") [
print(f"{solve_linear_system(matrix) = }") [5.0, -5.0, -3.0, 4.0, -11.0],
[1.0, -4.0, 6.0, -4.0, -10.0],
[-2.0, -5.0, 4.0, -5.0, -12.0],
[-3.0, -3.0, 5.0, -5.0, 8.0],
],
dtype=float,
)
print(f"Matrix:\n{example_matrix}")
print(f"{solve_linear_system(example_matrix) = }")

View File

@ -1,4 +0,0 @@
5.0 -5.0 -3.0 4.0 -11.0
1.0 -4.0 6.0 -4.0 -10.0
-2.0 -5.0 4.0 -5.0 -12.0
-3.0 -3.0 5.0 -5.0 8.0