Fortran高斯消元法求解方程组
(2016-08-20 01:21:42)
标签:
fortran高斯消元法线性方程组 |
分类: Fortran应用 |
module guass
contains
subroutine solve_guass(A,b,x,N)
implicit none
integer::N,i,j,k
real::A(N,N),b(N),x(N)
real::temp
subroutine solve_guass(A,b,x,N)
implicit none
integer::N,i,j,k
real::A(N,N),b(N),x(N)
real::temp
do k=1,N-1,1
do
i=k+1,N,1
temp=A(i,k)/A(k,k)
do j=k,N,1
A(i,j)=A(i,j)-temp*A(k,i)
b(i)=b(i)-temp*b(k)
end do
end do
end do
end do
call solve_uptri(A,b,x,N)
end subroutine
end subroutine
subroutine solve_uptri(A,b,x,N)
implicit none
integer::N
real::A(N,N),x(N),b(N)
integer::j,k
real::temp
implicit none
integer::N
real::A(N,N),x(N),b(N)
integer::j,k
real::temp
x(N)=b(N)/A(N,N)
do k=N-1,1,-1
temp=0
do
j=k+1,N,1
temp=temp+A(k,j)*x(j)
end do
x(k)=(b(k)-temp)/A(k,k)
end do
end subroutine
end do
end subroutine
end module
后一篇:Fortran复合梯形求积分