openGPMP
Open Source Mathematics Package
Functions/Subroutines
linsys_routines.f90 File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine solvelinearsystem (A, b, x, n)
 

Function/Subroutine Documentation

◆ solvelinearsystem()

subroutine solvelinearsystem ( real, dimension(n, n), intent(inout)  A,
real, dimension(n), intent(inout)  b,
real, dimension(n), intent(out)  x,
integer, intent(in)  n 
)

Definition at line 35 of file linsys_routines.f90.

36  implicit none
37  integer, intent(in) :: n
38  real, dimension(n, n), intent(inout) :: A
39  real, dimension(n), intent(inout) :: b
40  real, dimension(n), intent(out) :: x
41  real :: factor
42  integer :: i, j, k
43 
44  ! Forward elimination
45  do k = 1, n - 1
46  do i = k + 1, n
47  factor = a(i, k)/a(k, k)
48  a(i, k + 1:n) = a(i, k + 1:n) - factor*a(k, k + 1:n)
49  b(i) = b(i) - factor*b(k)
50  end do
51  end do
52 
53  ! Back substitution
54  x(n) = b(n)/a(n, n)
55  do i = n - 1, 1, -1
56  x(i) = (b(i) - dot_product(a(i, i + 1:n), x(i + 1:n)))/a(i, i)
57  end do
58