-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
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
Changes from 12 commits
579e99f
ad230e5
dc9fb8a
44ca32d
9c48e4b
d9db297
c5cae5f
135405a
0eb31fc
56ceb6a
2e2e767
f270415
3d1e8aa
6a0b6dd
8753484
87c2925
0f62cf6
579468b
ec2b578
3c5344c
4a85130
19f0edf
b1bc7ff
f7900b9
d519383
aac96dd
eafd037
769126f
6f00d68
45aefe8
3865376
33b85e6
d713c70
cf01b7e
0b19e0e
b9e172f
c588c9d
3966efc
07a8109
7d90336
2492d60
757c23e
301daa0
8c19a51
5d7dc32
fe4352b
a16c48e
58ad12e
ded4ad0
6772aeb
aeab790
f4296b0
88af17d
94acda9
619cc00
a726733
5e6b9fa
0a529e8
7e66a8e
2815287
6d648ec
9f6326e
07f5e9b
3b2ae9b
a566734
348c630
4b824d7
13fff37
df34643
f55e7ac
28a5410
30933f4
ea6ad3b
d5f04f6
caf3a97
6096e35
606667c
8594cc0
ed58bab
29f3dff
c5981ee
bc53093
074737b
5148009
52d7cfa
1d628ae
65a782b
dd16955
b81729f
8cc0a36
2b8c8b0
ec6aedd
a5b345f
20462d1
7ff1a46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide descriptive name for the parameter: Please provide descriptive name for the parameter: Please provide descriptive name for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide descriptive name for the parameter: Please provide descriptive name for the parameter: Please provide descriptive name for the parameter: |
||
""" | ||
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: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Please provide descriptive name for the parameter: Please provide descriptive name for the parameter: Please provide descriptive name for the parameter: |
||
""" | ||
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<<<<<# |
Uh oh!
There was an error while loading. Please reload this page.