Skip to content

implementation of Gaussian Elimination pivoting as a numerical linear algebra algorithm #10457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 95 commits into from
Oct 30, 2023
Merged
Changes from 12 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
579e99f
Adding new implementation
TheKidPadra Oct 14, 2023
ad230e5
Delete linear_algebra/src/GaussianEliminationpivoting.py
TheKidPadra Oct 14, 2023
dc9fb8a
Adding new implementation
TheKidPadra Oct 14, 2023
44ca32d
Delete linear_algebra/src/gaussianeliminationpivoting.py
TheKidPadra Oct 14, 2023
9c48e4b
Adding new implementation
TheKidPadra Oct 14, 2023
d9db297
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2023
c5cae5f
Merge branch 'TheAlgorithms:master' into master
TheKidPadra Oct 14, 2023
135405a
Delete linear_algebra/src/gaussianeliminationpivoting.py
TheKidPadra Oct 14, 2023
0eb31fc
Adding gaussianeliminationpivoting.py
TheKidPadra Oct 14, 2023
56ceb6a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2023
2e2e767
Merge branch 'TheAlgorithms:master' into master
TheKidPadra Oct 18, 2023
f270415
Update gaussianeliminationpivoting.py
TheKidPadra Oct 18, 2023
3d1e8aa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2023
6a0b6dd
Update gaussianeliminationpivoting.py
TheKidPadra Oct 18, 2023
8753484
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2023
87c2925
Merge branch 'TheAlgorithms:master' into master
TheKidPadra Oct 26, 2023
0f62cf6
Update gaussianeliminationpivoting.py
TheKidPadra Oct 26, 2023
579468b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
ec2b578
Update gaussianeliminationpivoting.py
TheKidPadra Oct 26, 2023
3c5344c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
4a85130
Update gaussianeliminationpivoting.py
TheKidPadra Oct 26, 2023
19f0edf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
b1bc7ff
Update gaussianeliminationpivoting.py
TheKidPadra Oct 26, 2023
f7900b9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
d519383
Update and rename gaussianeliminationpivoting.py to gaussian_eliminat…
TheKidPadra Oct 26, 2023
aac96dd
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
eafd037
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
769126f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
6f00d68
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
45aefe8
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
3865376
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
33b85e6
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
d713c70
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
cf01b7e
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
0b19e0e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
b9e172f
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
c588c9d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
3966efc
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
07a8109
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
7d90336
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
2492d60
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
757c23e
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
301daa0
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
8c19a51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
5d7dc32
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
fe4352b
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
a16c48e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
58ad12e
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
ded4ad0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
6772aeb
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
aeab790
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
f4296b0
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
88af17d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
94acda9
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
619cc00
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
a726733
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
5e6b9fa
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
0a529e8
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
7e66a8e
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
2815287
Delete linear_algebra/src/gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
6d648ec
Add files via upload
TheKidPadra Oct 26, 2023
9f6326e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
07f5e9b
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
3b2ae9b
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 26, 2023
a566734
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
348c630
Delete linear_algebra/src/gaussian_elimination_pivoting/text.py
TheKidPadra Oct 26, 2023
4b824d7
Add files via upload
TheKidPadra Oct 26, 2023
13fff37
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 26, 2023
df34643
Update linear_algebra/src/gaussian_elimination_pivoting/gaussian_elim…
TheKidPadra Oct 28, 2023
f55e7ac
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
28a5410
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2023
30933f4
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
ea6ad3b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2023
d5f04f6
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
caf3a97
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
6096e35
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2023
606667c
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
8594cc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2023
ed58bab
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
29f3dff
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 28, 2023
c5981ee
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
bc53093
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
074737b
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
5148009
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
52d7cfa
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 28, 2023
1d628ae
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 30, 2023
65a782b
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 30, 2023
dd16955
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 30, 2023
b81729f
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 30, 2023
8cc0a36
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 30, 2023
2b8c8b0
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 30, 2023
ec6aedd
Update gaussian_elimination_pivoting.py
TheKidPadra Oct 30, 2023
a5b345f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 30, 2023
20462d1
Update gaussian_elimination_pivoting.py
cclauss Oct 30, 2023
7ff1a46
Update gaussian_elimination_pivoting.py
cclauss Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions linear_algebra/src/gaussianeliminationpivoting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import numpy as np

def custom_pivoting(a: np.ndarray, n: int, i: int) -> int:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file linear_algebra/src/gaussianeliminationpivoting.py, please provide doctest for the function custom_pivoting

Please provide descriptive name for the parameter: a

Please provide descriptive name for the parameter: n

Please provide descriptive name for the parameter: i

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file linear_algebra/src/gaussianeliminationpivoting.py, please provide doctest for the function custom_pivoting

Please provide descriptive name for the parameter: a

Please provide descriptive name for the parameter: n

Please provide descriptive name for the parameter: i

"""
Selects the index of the minimum absolute value in the i-th column of a matrix.

Parameters:
- a (np.ndarray): The input matrix.
- n (int): The size of the matrix.
- i (int): The column index.

Returns:
- int: The index of the minimum absolute value in the i-th column.

Example:
>> a_matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=float)
>> custom_pivoting(a_matrix, 3, 1)
0
"""
min_index = i
for index in range(i + 1, n):
if abs(a[index][i]) < abs(a[min_index][i]):
min_index = index
return min_index

def custom_gauss_elimination_pivoting(a: list, b: list, n: int) -> list:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file linear_algebra/src/gaussianeliminationpivoting.py, please provide doctest for the function custom_gauss_elimination_pivoting

Please provide descriptive name for the parameter: a

Please provide descriptive name for the parameter: b

Please provide descriptive name for the parameter: n

"""
Solves a system of linear equations using Gaussian elimination with partial pivoting.

Parameters:
- a (list): The coefficient matrix.
- b (list): The constant vector.
- n (int): The size of the system.

Returns:
- list: The solution vector.

Example:
>>a_matrix = [[2, 3, 4], [1, -2, 3], [3, 4, 5]]
>> b_vector = [20, 9, 11]
>> custom_gauss_elimination_pivoting(a_matrix, b_vector, 3)
[1.0, 2.0, 3.0]
"""
result = []
for i in range(n - 1):
new_index = custom_pivoting(a, n, i)
a[i], a[new_index] = a[new_index], a[i]
b[i], b[new_index] = b[new_index], b[i]
pivot = a[i][i]
for j in range(i + 1, n):
m = -1 * a[j][i] / pivot
for k in range(0, n):
a[j][k] += m * a[i][k]
b[j] += m * b[i]

for p in range(n - 1, -1, -1):
result.append(b[p] / a[p][p])
for q in range(p - 1, -1, -1):
b[q] = b[q] - result[n - p - 1] * a[q][p]
return result




# Example usage:
# n_size = 3
# a_matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=float)
# b_vector = np.array([10, 11, 12], dtype=float)

# solution = custom_gauss_elimination_pivoting(a_matrix, b_vector, n_size)
# print("Solution:", solution)


#URL that points to Wikipedia or another similar explanation.
#>>>>>>URL:https://courses.engr.illinois.edu/cs357/su2013/lectures/lecture07.pdf<<<<<#