Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/augustocl/gauss_jordan_elimination
Scratch implementation of Gaussian Elimination algo in Julia
https://github.com/augustocl/gauss_jordan_elimination
algorithm gauss-elimination gauss-jordan gauss-jordan-elimination julialang
Last synced: 2 days ago
JSON representation
Scratch implementation of Gaussian Elimination algo in Julia
- Host: GitHub
- URL: https://github.com/augustocl/gauss_jordan_elimination
- Owner: AugustoCL
- License: mit
- Created: 2020-09-30T16:25:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-09T03:25:20.000Z (over 3 years ago)
- Last Synced: 2024-11-21T15:27:11.542Z (2 months ago)
- Topics: algorithm, gauss-elimination, gauss-jordan, gauss-jordan-elimination, julialang
- Language: Julia
- Homepage:
- Size: 52.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Gauss-Jordan Elimination
This repo implements **from scratch** the **Gaussian Elimination** algorithm in [Julia Lang](julialang.org/).If you need to refresh your memory about the technique, I suggest you read the [wikipedia page](https://en.wikipedia.org/wiki/Gaussian_elimination) of the method, which has a great introduction and applications in Linear Algebra disciplines.
## Example of the operation
![](imgs/gauss-jordan-operation.png)## Function implemented
```julia
function gauss_jordan(A::Matrix{T}) where {T<:Number}
# convert to float to avoid InexactError: Int64()
(T <: Integer) && (A = convert.(Float64, A))# check if matrix is singular
m, n = size(A)
if m == n
@assert det(A) ≠ 0.0 "Must insert a non-singular matrix"
else
@assert det(A[:,1:end-1]) ≠ 0.0 "Must insert a non-singular matrix or a system matrix [A b]"
endfor i ∈ axes(A, 1)
if A[i,i] == 0.0 # check if need swap rows
swap_rows(i, m)
end@. A[i,:] = A[i,:] / A[i,i] # divide pivot line by pivot element
for j ∈ axes(A, 1) # iterate each line for each pivot column, except pivot line
if j ≠ i # jump pivot line
@. A[j,:] = A[j,:] - A[i,:]*A[j,i] # apply gauss jordan in each line
end
end
endreturn A
endfunction swap_rows(i::T, nlinha::T) where {T<:Integer}
for n ∈ (i+1):nlinha # iterate over lines above to check if could be swap
if A[n,i] ≠ 0.0 # condition to swap row
L = copy(A[i,:]) # copy line to swap
A[i,:] = A[n,:] # swap occur
A[n,:] = L
break
end
end
end
```## Benchmark inputing Int vs Float
![](imgs/bench-float-int.png)