Presentation is loading. Please wait.

Presentation is loading. Please wait.

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 1 5 a.

Similar presentations


Presentation on theme: "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 1 5 a."— Presentation transcript:

1 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 1 5 a =

2 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

3 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). -1 2 2 4 3 1 1 1 1 1 1 1 a= b= e=transpose(a) c=matmul(e,b) d=a+c

4 program mat1 integer,dimension(3,3)::a,b,c,d,e integer::i,j a(1,1)=-1 a(1,2)=2 a(1,3)=2 a(2,1)=4 a(2,2)=3 a(2,3)=1 a(1,3)=2 a(3,1)=1 a(3,2)=1 a(3,3)=1 do i=1,3 do j=1,3 b(i,j)=1 e=transpose(a) c=matmul(e,b) d=a+c end do print*,"a=",a," b=",b," c=",c," d=",d end program mat1 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

5 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 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

6 Write down a program that calculates and print the elements of given matrix using do loop.

7 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 do i=1,5 print"(3(5i4))",a(i,1:5) end do end program mat3

8

9 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

10 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

11 Write down a program that writes the results of the multiplication table as following.

12 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

13

14 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 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


Download ppt "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 1 5 a."

Similar presentations


Ads by Google