Chapter 9: Basic Matrix/Vector Operations

## HRRRR

Computes the Hadamard product of two real rectangular matrices.

#### Required Arguments

A — Real NRA by NCA rectangular matrix.   (Input)

B — Real NRB by NCB rectangular matrix.   (Input)

C — Real NRC by NCC rectangular matrix containing the Hadamard product of A and B.   (Output)
If A is not needed, then C can share the same storage locations as A. Similarly, if B is not needed, then C can share the same storage locations as B.

#### Optional Arguments

NRA — Number of rows of A.   (Input)
Default: NRA = size (A,1).

NCA — Number of columns of A.   (Input)
Default: NCA = size (A,2).

LDA — Leading dimension of A exactly as specified in the dimension statement of the calling program.   (Input)
Default: LDA = size (A,1).

NRB — Number of rows of B.   (Input)
NRB must be equal to NRA.
Default: NRB = size (B,1).

NCB — Number of columns of B.   (Input)
NCB must be equal to NCA.
Default: NCB = size (B,2).

LDB — Leading dimension of B exactly as specified in the dimension statement of the calling program.   (Input)
Default: LDB = size (B,1).

NRC — Number of rows of C.   (Input)
NRC must be equal to NRA.
Default: NRC = size (C,1).

NCC — Number of columns of C.   (Input)
NCC must be equal to NCA.
Default: NCC = size (C,2).

LDC — Leading dimension of C exactly as specified in the dimension statement of the calling program.   (Input)
Default: LDC = size (C,1).

#### FORTRAN 90 Interface

Generic:          CALL HRRRR (A, B, C [,…])

Specific:          The specific interface names are S_HRRRR and D_HRRRR.

#### FORTRAN 77 Interface

Single:             CALL HRRRR (NRA, NCA, A, LDA, NRB, NCB, B, LDB, NRC, NCC, C, LDC)

Double:           The double precision name is DHRRRR.

#### Description

The routine HRRRR computes the Hadamard product of two real matrices A and B and returns a real matrix C, where Cij = AijBij.

#### Example

Compute the Hadamard product of two 4 × 4 real matrices. The output matrix will be a 4 × 4 real matrix.

USE HRRRR_INT

USE WRRRN_INT

IMPLICIT   NONE

!                                 Declare variables

INTEGER    NCA, NCB, NCC, NRA, NRB, NRC

PARAMETER  (NCA=4, NCB=4, NCC=4, NRA=4, NRB=4, NRC=4)

!

REAL       A(NRA,NCA), B(NRB,NCB), C(NRC,NCC)

!                                 Set values for A

!                                 A = ( -1.0  0.0 -3.0  8.0 )

!                                     (  2.0  1.0  7.0  2.0 )

!                                     (  3.0 -2.0  2.0 -6.0 )

!                                     (  4.0  1.0 -5.0 -8.0 )

!

!                                 Set values for B

!                                 B = (  2.0  3.0  0.0 -10.0 )

!                                     (  1.0 -1.0  4.0   2.0 )

!                                     ( -1.0 -2.0  7.0   1.0 )

!                                     (  2.0  1.0  9.0   0.0 )

!

DATA A/-1.0, 2.0, 3.0, 4.0, 0.0, 1.0, -2.0, 1.0, -3.0, 7.0, 2.0, &

-5.0, 8.0, 2.0, -6.0, -8.0/

DATA B/2.0, 1.0, -1.0, 2.0, 3.0, -1.0, -2.0, 1.0, 0.0, 4.0, 7.0, &

9.0, -10.0, 2.0, 1.0, 0.0/

!                                 Compute Hadamard product of A and B

CALL HRRRR (A, B, C)

!                                 Print results

CALL WRRRN ('C = A (*) B', C)

END

#### Output

C = A (*) B
1       2       3       4
1   -2.00    0.00    0.00  -80.00
2    2.00   -1.00   28.00    4.00
3   -3.00    4.00   14.00   -6.00
4    8.00    1.00  -45.00    0.00

 http://www.vni.com/PHONE: 713.784.3131FAX:713.781.9260