next up previous contents
Next: Vector Subscripts / MAXLOC Up: Operations on arrays and Previous: Operations on arrays and

Solution

Here is the program:

PROGRAM A_and_X

 IMPLICIT NONE
 INTEGER, PARAMETER,            &
          DIMENSION(2,3) :: A = &
          RESHAPE((/-4,6,5,-7,9,8/),(/2,3/))
 REAL,    PARAMETER,            &
          DIMENSION(5)   :: X = &
          (/1.5,-1.9,1.7,-1.2,0.3/)
 INTEGER                 :: M, N

  M = SIZE(A,1) ! # elts in dim 1
  N = SIZE(A,2) ! # elts in dim 2

  PRINT*, "M and N are", M, N

  PRINT*, A(1,:)
  PRINT*, A(2,:)

! i)
  PRINT*, "The sum of the product of the columns of A",&
           SUM(PRODUCT(A,DIM=1))
! ii)
  PRINT*, "The product of the sum of the row elements of A", &
           PRODUCT(SUM(A,DIM=2))
! iii)
  PRINT*, "The sum of squares of the elements of X",&
           SUM(X*X)
! iii) ALT
  PRINT*, "The sum of squares of the elements of X",&
           DOT_PRODUCT(X,X)
! iv)
  PRINT*, "The mean of the elements of X", &
           SUM(X)/SIZE(X)
! v)
  PRINT*, "The sum of the positive elements of X", &
           SUM(X,MASK=X.GT.0)
! vi)
  PRINT*, "The infinity norm of X", &
           MAXVAL(ABS(X))
! vii)
  PRINT*, "The one norm of A", &
           MAXVAL(SUM(ABS(A),1))

END PROGRAM A_and_X


next up previous contents
Next: Vector Subscripts / MAXLOC Up: Operations on arrays and Previous: Operations on arrays and

©University of Liverpool, 1997
Thu May 29 10:11:26 BST 1997
Not for commercial use.