PROGRAM Tridiagonal
!The number of variable or number of equations is n.
!The coefficient matrix=a(ij), i, j=1,2,3,...,n.
!The lower triangular matrix=l(ij), i, j=1,2,3,...,n.
!The upper matrix=u(ij), i, j=1,2,3,...,n.
!b(i), i=1,2,3,...,n, the constants of the of the equations.
!z(i), i=1,2,3,...,n.
!x(i), i=1,2,3,...,n.
integer::n,i,j,k,m
real:: a(5),b(5),c(5),p(5),q(5),r(5),x(5),z(5),d(5)
open(9,file="input.dat")
open(10,file="output10")
read(9,*)n
read(9,*)(a(j),j=1,n)
read(9,*)(b(j),j=1,n-1)
read(9,*)(c(j),j=2,n)
read(9,*)(d(j),j=1,n)
write(10,*)"a="," ",(a(j),j=1,n)
write(10,*)" "
write(10,*)"b="," ",(b(j),j=1,n-1)
write(10,*)" "
write(10,*)"c="," ",(c(j),j=2,n)
write(10,*)" "
write(10,*)"d="," ",(d(j),j=1,n)
r(1)=a(1)
do i=2,n
q(i)=c(i)
p(i-1)=b(i-1)/r(i-1)
r(i)=a(i)-p(i-1)*q(i)
write(10,*)"i=",i,"p,q,r=",p(i),q(i),r(i)
enddo
write(10,*)" "
write(10,*)"p="," ",(p(j),j=1,n-1)
write(10,*)" "
write(10,*)"q="," ",(q(j),j=2,n)
write(10,*)" "
write(10,*)"r="," ",(r(j),j=1,n)
write(10,*)" "
z(1)=d(1)/r(1)
do i=2,n
z(i)=(d(i)-q(i)*z(i-1))/r(i)
enddo
x(n)=z(n)
do i=n-1,1,-1
x(i)=z(i)-p(i)*x(i+1)
enddo
write(10,*)" "
write(10,*)"z="," ",(z(j),j=2,n)
write(10,*)" "
write(10,*)"x="," ",(x(j),j=1,n)
end PROGRAM
!The number of variable or number of equations is n.
!The coefficient matrix=a(ij), i, j=1,2,3,...,n.
!The lower triangular matrix=l(ij), i, j=1,2,3,...,n.
!The upper matrix=u(ij), i, j=1,2,3,...,n.
!b(i), i=1,2,3,...,n, the constants of the of the equations.
!z(i), i=1,2,3,...,n.
!x(i), i=1,2,3,...,n.
integer::n,i,j,k,m
real:: a(5),b(5),c(5),p(5),q(5),r(5),x(5),z(5),d(5)
open(9,file="input.dat")
open(10,file="output10")
read(9,*)n
read(9,*)(a(j),j=1,n)
read(9,*)(b(j),j=1,n-1)
read(9,*)(c(j),j=2,n)
read(9,*)(d(j),j=1,n)
write(10,*)"a="," ",(a(j),j=1,n)
write(10,*)" "
write(10,*)"b="," ",(b(j),j=1,n-1)
write(10,*)" "
write(10,*)"c="," ",(c(j),j=2,n)
write(10,*)" "
write(10,*)"d="," ",(d(j),j=1,n)
r(1)=a(1)
do i=2,n
q(i)=c(i)
p(i-1)=b(i-1)/r(i-1)
r(i)=a(i)-p(i-1)*q(i)
write(10,*)"i=",i,"p,q,r=",p(i),q(i),r(i)
enddo
write(10,*)" "
write(10,*)"p="," ",(p(j),j=1,n-1)
write(10,*)" "
write(10,*)"q="," ",(q(j),j=2,n)
write(10,*)" "
write(10,*)"r="," ",(r(j),j=1,n)
write(10,*)" "
z(1)=d(1)/r(1)
do i=2,n
z(i)=(d(i)-q(i)*z(i-1))/r(i)
enddo
x(n)=z(n)
do i=n-1,1,-1
x(i)=z(i)-p(i)*x(i+1)
enddo
write(10,*)" "
write(10,*)"z="," ",(z(j),j=2,n)
write(10,*)" "
write(10,*)"x="," ",(x(j),j=1,n)
end PROGRAM
Comments
Post a Comment