Fortran几个函数(DOT_PRODUCT+MATMUL+TRANSPOSE+RESHAPE)

 DOT_PRODUCT函数(点积)

    DOT_PRODUCT(VECTOR_A, VECTOR_B)  computes the dot product multiplication of two vectors  VECTOR_A and VECTOR_B. The two vectors may be either numeric or logical and must be arrays of rank one and of equal size. If the vectors are INTEGER or REAL, the result is SUM(VECTOR_A*VECTOR_B). If the vectors are COMPLEX, the result is SUM(CONJG(VECTOR_A)*VECTOR_B). If the vectors are LOGICAL, the result is ANY(VECTOR_A .AND. VECTOR_B).
    Examples
    DOT_PRODUCT ((/1, 2, 3/), (/3, 4, 5/)) has the value 26 (calculated as follows: ((1 x 3) + (2 x 4) + (3 x 5)) = 26 ).
    DOT_PRODUCT ((/ (1.0, 2.0), (2.0, 3.0) /), (/ (1.0, 1.0), (1.0, 4.0) /)) has the value (17.0, 4.0). !complex function application.
    DOT_PRODUCT ((/ .TRUE., .FALSE. /), (/ .FALSE., .TRUE. /)) has the value false.
   The following shows another example:
   I = DOT_PRODUCT((/1,2,3/), (/4,5,6/)) ! returns  the value 32 
 
    MATMUL函数(矩阵的相乘)
     Performs a matrix multiplication on numeric or logical arguments.
    A is matrix
    [ 2 3 4 ] [ 3 4 5 ],B is matrix [ 2 3 ] [ 3 4 ] [ 4 5 ],X is vector (1, 2), and Y is vector (1, 2, 3).
    The result of MATMUL (A, B) is the matrix-matrix product AB with the value
            [ 29 38 ] [ 38 50 ].
    The result of MATMUL (X, A) is the vector-matrix product XA with the value (8, 11, 14).
    The result of MATMUL (A, Y) is the matrix-vector product AY with the value (20, 26).
    The following shows another example:
    INTEGER a(2,3), b(3,2), c(2), d(3), e(2,2), f(3), g(2) a = RESHAPE((/1, 2, 3, 4, 5, 6/), (/2, 3/)) ! a is 1 3 5 ! 2 4 6 b = RESHAPE((/1, 2, 3, 4, 5, 6/), (/3, 2/)) ! b is 1 4 ! 2 5 ! 3 6 c = (/1, 2/) ! c is [1 2] d = (/1, 2, 3/) ! d is [1 2 3] e = MATMUL(a, b) ! returns 22 49 ! 28 64 f = MATMUL(c,a) ! returns [5 11 17] g = MATMUL(a,d) ! returns [22 28] WRITE(*,*) e, f, g END

     TRANSPOSE函数(数组转置)
     Description:
    Transpose an array of rank two. Element (i, j) of the result has the value MATRIX(j, i), for all i, j.
    B is the array
      [ 2 3 4 ] [ 5 6 7 ] [ 8 9 1 ].TRANSPOSE (B) has the value [ 2 5 8 ] [ 3 6 9 ] [ 4 7 1 ].
    The following shows another example:
    INTEGER array(2, 3), result(3, 2) array = RESHAPE((/1, 2, 3, 4, 5, 6/), (/2, 3/)) ! array is 1 3 5 ! 2 4 6 result = TRANSPOSE(array) ! result is 1 2 ! 3 4 ! 5 6 END?

       RESHAPE函数(矩阵重组)
    Description:
    Reshapes SOURCE to correspond to SHAPE. If necessary, the new array may be padded with elements from PAD or permuted as defined by ORDER.
    RESHAPE ((/3, 4, 5, 6, 7, 8/), (/2, 3/)) has the value
    [ 3 5 7 ] [ 4 6 8 ].RESHAPE ((/3, 4, 5, 6, 7, 8/), (/2, 4/), (/1, 1/), (/2, 1/)) has the value [ 3 4 5 6 ] [ 7 8 1 1 ].
    The following shows another example:
    INTEGER AR1( 2, 5) REAL F(5,3,8) REAL C(8,3,5) AR1 = RESHAPE((/1,2,3,4,5,6/),(/2,5/),(/0,0/),(/2,1/)) ! returns 1 2 3 4 5 ! 6 0 0 0 0 ! ! Change Fortran array order to C array order C = RESHAPE(F, (/8,3,5/), ORDER = (/3, 2, 1/)) END

Fortran几个函数(DOT_PRODUCT+MATMUL+TRANSPOSE+RESHAPE) - 云卷云舒 - 飞龙在天的小窝儿^_^
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值