Fortran几个函数(DOT_PRODUCT+MATMUL+TRANSPOSE+RESHAPE)
2017-10-15 18:23
537 查看
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
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)
- numpy的常用函数reshape、matmul
- URL处理几个关键的函数parse_url、parse_str与http_build_query
- 几个字符串操作的汇编函数
- C语言面试必须会的几个字符串操作函数原型strcpy,strcmp,strlen,strcat
- 针对javascript的几个对象的扩充函数
- 收集最近用到的几个oracle函数
- hashmap的几个重要函数
- 几个返回字符串或者数组长度的函数
- 介绍几个C++程序中关于"时间"的函数
- 学习笔记----几个Oracle函数
- C中几个常见的测试字符的函数
- Delphi,几个实用的HTML解析函数
- 几个操作函数的具体定义
- python几个排序函数 sort sorted argsort
- 几个重要的库函数strcpy , strncpy, memcpy实现
- stl alogrithm 几个函数的备忘录
- 关于处理小数点位数的几个oracle函数()
- 几个常用的Oracle分析函数
- 几个小函数