mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
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:
parent
31c424fc86
commit
48418280b1
|
@ -540,8 +540,7 @@
|
|||
* [Lu Decomposition](linear_algebra/lu_decomposition.py)
|
||||
* Src
|
||||
* [Conjugate Gradient](linear_algebra/src/conjugate_gradient.py)
|
||||
* Gaussian Elimination Pivoting
|
||||
* [Gaussian Elimination Pivoting](linear_algebra/src/gaussian_elimination_pivoting/gaussian_elimination_pivoting.py)
|
||||
* [Gaussian Elimination Pivoting](linear_algebra/src/gaussian_elimination_pivoting.py)
|
||||
* [Lib](linear_algebra/src/lib.py)
|
||||
* [Polynom For Points](linear_algebra/src/polynom_for_points.py)
|
||||
* [Power Iteration](linear_algebra/src/power_iteration.py)
|
||||
|
|
|
@ -1,15 +1,5 @@
|
|||
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:
|
||||
"""
|
||||
|
@ -87,15 +77,18 @@ def solve_linear_system(matrix: np.ndarray) -> np.ndarray:
|
|||
|
||||
if __name__ == "__main__":
|
||||
from doctest import testmod
|
||||
from pathlib import Path
|
||||
|
||||
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:
|
||||
print(f"Matrix:\n{matrix}")
|
||||
print(f"{solve_linear_system(matrix) = }")
|
||||
example_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,
|
||||
)
|
||||
|
||||
print(f"Matrix:\n{example_matrix}")
|
||||
print(f"{solve_linear_system(example_matrix) = }")
|
|
@ -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
|
Loading…
Reference in New Issue
Block a user