matrix addition and multiplication

SYNOPSIS

#include "matrix.h"
MAT     *m_add(MAT *A, MAT *B, MAT *C)
MAT     *m_mlt(MAT *A, MAT *B, MAT *C)
MAT     *m_sub(MAT *A, MAT *B, MAT *C)
MAT     *sm_mlt(double s, MAT *A, MAT *OUT)
#include "zmatrix.h"
ZMAT    *zm_add(ZMAT *A, ZMAT *B, ZMAT *C)
ZMAT    *zm_mlt(ZMAT *A, ZMAT *B, ZMAT *C)
ZMAT    *zm_sub(ZMAT *A, ZMAT *B, ZMAT *C)
ZMAT    *zsm_mlt(complex s, ZMAT *A, ZMAT *OUT)

DESCRIPTION

The functions m_add(), zm_add() adds the matrices A and B and puts the result in C. If C is NULL, or is too small to contain the sum of A and B, then the matrix is resized to the correct size, which is then returned. Otherwise the matrix C is returned. The functions, m_sub(), zm_sub() subtracts the matrix B from A and puts the result in C. If C is NULL, or is too small to contain the sum of A and B, then the matrix is resized to the correct size, which is then returned. Otherwise the matrix C is returned. Similarly, m_mlt() multiplies the matrices A and B and puts the result in C. Again, if C is NULL or too small, then a matrix of the correct size is created which is returned. The routines sm_mlt(), zsm_mlt() above puts the results of multiplying the matrix A by the scalar s in the matrix OUT. If, on entry, OUT is NULL, or is too small to contain the results of this operation, then OUT is resized to have the correct size. The result of the operation is returned. This operation may be performed in situ. That is, you may use A == OUT. The routines m_add(), m_sub() and sm_mlt() routines and their complex counterparts can work in situ\/; that is, C need not be different to either A or B. However, m_mlt() and zm_mlt() will raise an E_INSITU error if A == C or B == C. These routines avoid thrashing on virtual memory machines.

EXAMPLE

MAT    *A, *B, *C;
Real   alpha;
  ......
C = m_add(A,B,MNULL);  /* C = A+B */
m_sub(A,B,C);          /* C = A-B */
sm_mlt(alpha,A,C);     /* C = alpha.A */
m_mlt(A,B,C);          /* C = A.B */

SEE ALSO: v_add(), mv_mlt(), sv_mlt(), zv_add(), zmv_mlt(), zv_mlt().

SOURCE FILE: matop.c, zmatop.c