Guass-Jordan解线性方程组



subroutine UWAPIPE_GuassJordan(n,K,dF,du)
!
!! solve linear equations using Guass-Jordan method
use UWAPIPE_module
implicit none

integer, intent(in) :: n
real(kind=gp), dimension(n,n), intent(in) :: K
real(kind=gp), dimension(n), intent(in) :: dF
real(kind=gp), dimension(n), intent(out) :: du

integer :: i, j
real(kind=gp), dimension(n,n+1) :: Mat
real(kind=gp), dimension(n+1) :: temp

Mat(:,1:n) = K(:,:)
Mat(:,n+1) = dF(:)
du = 0.0_gp
do i = 1, n
do j = i+1, n
if (abs(Mat(j,i))>abs(Mat(i,i))) then
temp(i:n+1) = Mat(i,i:n+1)
Mat(i,i:n+1) = Mat(j,i:n+1)
Mat(j,i:n+1) = temp(i:n+1)
end if
end do
Mat(i,i:n+1) = Mat(i,i:n+1)/Mat(i,i)
do j = 1, n
if (j /= i) then
Mat(j,i:n+1) = Mat(j,i:n+1) – Mat(j,i)/Mat(i,i)*Mat(i,i:n+1)
end if
end do
end do
du = Mat(:,n+1)
end subroutine UWAPIPE_GuassJordan

Advertisements

About yhtian

I am an academic researcher working on Offshore Geotechnical Engineering. My blog aims to write down some work related trivial things and tricks about software, programming. It is basically a memo for me to back up some thoughts and small details. But I am more than happy if someone would visit and discuss.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s