Download 1 a(1,3)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Matrix a is given as follows. Write a program calculate Matrix b
as transpose of matrix a and matrix n as multiplication of matrices
a and b.
2 4
a=
1 5
program mat_cal
integer,dimension(2,2)::a,b,n
integer::i
a(1,1)=2
a(1,2)=4
a(2,1)=1
a(2,2)=5
b=transpose (a)
n=matmul(a,b)
print*,"Martix_a=",a,"Matrix_b=",b,"Matrix_n=",n
do i=1,2
print "(3(2i3,a))",a(i,1:2)," ",b(i,1:2)," ",n(i,1:2)," "
end do
endprogram mat_cal
Matrix a and b are given as follows. Write a program calculate and
print Matrix a, b, c and d. (Write same program using reshape
function also).
a=
-1 2 2
4 3 1
1 1 1
b=
1 1 1
1 1 1
1 1 1
e=transpose(a)
c=matmul(e,b)
d=a+c
program mat1
a(3,3)=1
integer,dimension(3,3)::a,b,c,d,e
do i=1,3
integer::i,j
do j=1,3
a(1,1)=-1
b(i,j)=1
a(1,2)=2
e=transpose(a)
a(1,3)=2
c=matmul(e,b)
a(2,1)=4
print*," "
d=a+c
a(2,2)=3
do i=1,3
end do
end do
a(2,3)=1
print "(4(3i3,a))",a(i,1:3)," ",b(i,1:3),"
",c(i,1:3)," ",d(i,1:3)
print*,"a=",a," b=",b,"
a(1,3)=2
end do
c=",c," d=",d
a(3,1)=1
end program mat1
a(3,2)=1
program mat2
integer,dimension(3,3)::a,b,c,d,e
integer::i,j
a=reshape((/-1,4,1,2,3,1,2,1,1/),(/3,3/))
do i=1,3
do j=1,3
b(i,j)=1
e=transpose(a)
c=matmul(e,b)
d=a+c
end do
end do
print*," "
do i=1,3
print "(4(3i3,a))",a(i,1:3)," ",b(i,1:3)," ",c(i,1:3)," ",d(i,1:3)
end do
end program mat2
Write down a program that calculates and print the
elements of given matrix using do loop.
program mat3
integer,dimension(5,5)::a
integer::i,j
do i=1,5
do j=1,5
if (i==j) then
a(i,j)=i**2
else
a(i,j)=(i+j)-1
end if
end do
end do
do i=1,5
print"(3(5i4))",a(i,1:5)
end do
end program mat3
program home10
integer,dimension(5,5)::A,B,C,D
integer::i,j
A=reshape((/1,2,3,4,5,2,4,4,5,6,3,4,9,6,7,4,5,6,16,8,5,6,7,8,25/),
(/5,5/))
do i=1,5
do j=1,5
if (i==j)then
B(i,j)=7
else
B(i,j)=0
end if
end do
end do
C=A+B
D=5*A-3*B
print*,"
Matrix A","
","Matrix B"
do i=1,5
print"(2(5i4,a))",A(i,1:5)," ",B(i,1:5)
end do
print*," "
print*,"
Matrix C","
","Matrix D"
do i=1,5
print"(2(5i4,a))",C(i,1:5)," ",D(i,1:5)
end do
end program home10
Write down a program that writes the results of the
multiplication table as following.
program multi_square
!------------------------------------------------------------!This program shows the multipication square.
!------------------------------------------------------------!variable declerations
integer::i,j
integer,dimension(12)::x
print*,"
1 2 3 4 5 6 7 8 9 10 11 12"
print*," x"
!make the calculations
do i=1,12
do j=1,12
x(j)=i*j
end do
!print the outputs
print "(i6,12i4)",i,x(1:12)
end do
end program multi_square
program mat2
integer,dimension(3,3)::a,b,c,d,e
integer::i,j
a=reshape((/-1,4,1,2,3,1,2,1,1/),(/3,3/))
do i=1,3
do j=1,3
b(i,j)=1
e=transpose(a)
c=matmul(e,b)
d=a+c
end do
end do
print*," "
do i=1,3
print "(4(3i3,a))",a(i,1:3)," ",b(i,1:3)," ",c(i,1:3)," ",d(i,1:3)
end do
end program mat2
Related documents