! 譁�ｭ励さ繝ｼ繝峨�utf-8
! 閾ｪ逕ｱ蠖｢蠑上�fortran縺ｧ譖ｸ縺�※縺�∪縺吶�
! 繧ｬ繧ｦ繧ｹ縺ｮ豸亥悉豕輔〒騾｣遶�1谺｡譁ｹ遞句ｼ渋(i,j)*x(j)=b(i)繧定ｧ｣縺上し繝悶Ν繝ｼ繝√Φ
! gausu 縺ｮ菴ｿ逕ｨ萓九�
implicit real*8(a-h, o-z)
dimension a(5,5),x(5),b(5)
! 萓�1遲斐∴:x(1)=1.,x(2)=2.,x(3)=3.
!a(1,1)=1.;  a(1,2)=2.;  a(1,3)=3.
!a(2,1)=1.;  a(2,2)=3.;  a(2,3)=3.
!a(3,1)=2.;  a(3,2)=5.;  a(3,3)=7.
!b(1)=14.
!b(2)=16.
!b(3)=33.
!
! 萓�2遲斐∴:x(1)=2.,x(2)=3.,x(3)=-3.,x(4)=2.
!a(1,1)= 4.;a(1,2)=-1.;a(1,3)=-1.;a(1,4)= 0.
!a(2,1)=-1.;a(2,2)= 4.;a(2,3)= 0.;a(2,4)=-1.
!a(3,1)=-1.;a(3,2)= 0.;a(3,3)= 4.;a(3,4)=-1.
!a(4,1)= 0.;a(4,2)=-1.;a(4,3)=-1.;a(4,4)= 4.
!b(1)=8.;b(2)=8.;b(3)=-16.;b(4)=8.
!
!萓�3遲斐∴:x(1)=1.,x(2)=0.,x(3)=1.,x(4)=0.,x(5)=2.
a(1,1)=1.;a(1,2)=1.;a(1,3)=1.;a(1,4)=0.;a(1,5)=0.
a(2,1)=0.;a(2,2)=1.;a(2,3)=1.;a(2,4)=1.;a(2,5)=0.
a(3,1)=0.;a(3,2)=0.;a(3,3)=1.;a(3,4)=1.;a(3,5)=1.
a(4,1)=1.;a(4,2)=0.;a(4,3)=0.;a(4,4)=1.;a(4,5)=1.
a(5,1)=1.;a(5,2)=1.;a(5,3)=0.;a(5,4)=0.;a(5,5)=1.
b(1)=2.;b(2)=1.;b(3)=3.;b(4)=3.;b(5)=3.
!
n=5
!
print*,'a='
do i=1,n
print*, (a(i,j),j=1,n)
end do
!
print*,'b='
print*, (b(i),i=1,n)
!
call gausu(n,a,x,b)
print*,'x='
print*, (x(i),i=1,n)
end
!
subroutine gausu(n,a,x,b)
implicit real*8(a-h, o-z)
dimension a(n,n),x(n),b(n)
!
!繧ｬ繧ｦ繧ｹ縺ｮ豸亥悉豕輔�蜿り�→縺励◆縺ｮ縺ｯ縲�
!蜷榊叙莠ｮ縲後☆縺�′縺上�縺｣縺上☆12 邱壼ｽ｢險育ｮ励�(譛晏画嶌蠎�)p.10-15
!
do k=1,n-1  !a(k,k)繧呈ｶ亥悉
do i=k+1,n  !k+1陦後°繧穎陦後∪縺ｧ
do j=k+1,n    !k+1蛻励°繧穎蛻励∪縺ｧ
   a(i,j)=a(i,j)-a(k,j)*a(i,k)/a(k,k)
end do
   b(i)=b(i)-b(k)*a(i,k)/a(k,k)
end do
end do
!
! 蠕碁莉｣蜈･
x(n)=b(n)/a(n,n)
do k=n,1,-1
   akjxj=0.d0
do j=k+1,n
   akjxj=akjxj+a(k,j)*x(j)
end do
   x(k)=(b(k)-akjxj)/a(k,k)
end do
!
return
end
!
!