|
+ - * / **
|
can be applied to conformable arrays
Effect:
A op B <=> perform the operation op on each pair of values in A and B op = +, -, *, /, ** |
REAL, DIMENSION(3,3) :: A1 REAL, DIMENSION(3,3) :: A2 REAL, DIMENSION(3,3) :: B B = A2 + A1 |
is the same as:
REAL, DIMENSION(3,3) :: A1
REAL, DIMENSION(3,3) :: A2
REAL, DIMENSION(3,3) :: B
integer i, j;
DO i = 1, 3
DO j = 1, 3
B(i,j) = A2(i,j) + A1(i,j)
END DO
END DO
|
NOTE:
A * B |
is NOT the same as the matrix * matrix multiplication operation that we have defined in C++
+- -+ +- -+ +- -+ | 1 2 | | -1 2 | | 1*-1 2*2 | | | * | | = | | | 3 4 | | -3 4 | | 3*-3 4*4 | +- -+ +- -+ +- -+ |
REAL, DIMENSION(2,2) :: A REAL, DIMENSION(2,2) :: B B = SQRT(A) !! Square root |
|
When array variables and scalars are used in
an arithmetic expression ,
the scalar is first
converted into an array of the same shape
and then the corresponding array operation is applied. |
REAL, DIMENSION(3,3) :: A REAL, DIMENSION(3,3) :: B B = A + 10 or: B = 10 + A |
WHERE (array-logical-expression)
array = array-expression
...
[
ELSEWHERE
array = array-expression
...
]
END WHERE
|
|
+- -+
| 1 2 |
A = | |
| 3 4 |
+- -+
+- -+
| 4 1 |
B = | |
| 7 1 |
+- -+
WHERE (A > B)
A = 1
B = 0
ELSEWHERE
B = 1
A = 0
END WHERE
|
SUM(v): sum al elements in v (vector or matrix) DOT_PRODUCT(v1, v2): compute the vector dot-product of v1 and v2 MATMUL(A1, A2): (real) matrix multiplication |
REAL, DIMENSION(2,2) :: A REAL, DIMENSION(3) :: v REAL :: x x = SUM(v) x = SUM(A) |
REAL, DIMENSION(3) :: v1, v2 REAL :: x x = DOT_PRODUCT(v1, v2) |
REAL A(2,3) REAL B(3,2) REAL C(2,2) ! Output matrices REAL D(3,3) C = MATMUL(A, B) D = MATMUL(B, A) |