求fortran编写的三个矩阵相乘的程序,三个矩阵设置成(m,m)形状的.
问题描述:
求fortran编写的三个矩阵相乘的程序,三个矩阵设置成(m,m)形状的.
矩阵是T*K*T的转置.最好能设置成两重循环,即do i=1,m
do j=1,m
答
你的问题可进行简化,fortran中可以直接用matmul函数进行矩阵的乘积,下面是我编的程序愿您满意!其中矩阵C为矩阵A的转置,有问题可以问我
program main
implicit none
integer::A(3,3)=(/1,2,3,4,5,6,7,8,9/)
integer::B(3,3)=(/9,8,7,6,5,4,3,2,1/)
integer::C(3,3)=0
integer::D(3,3)=0
integer::i,j
do j=1,3
C(j,:)=A(:,j)!矩阵A的转置赋给C
enddo
write(*,*)"矩阵A=:"
write(*,"(3I3/)")((A(i,j),j=1,3),i=1,3)
write(*,*)"矩阵B=:"
write(*,"(3I3/)")((B(i,j),j=1,3),i=1,3)
write(*,*)"矩阵C=:"
write(*,"(3I3/)")((C(i,j),j=1,3),i=1,3)
D=matmul(A,B)
write(*,*)"矩阵A*B=:"
write(*,"(3I8/)")((D(i,j),j=1,3),i=1,3)
D=matmul(D,C)
write(*,*)"矩阵A*B*C=:"
write(*,"(3I8/)")((D(i,j),j=1,3),i=1,3)
stop
end