Rescaling a fixed size matrix (original) (raw)

next up previous contents
Next: Transposing a fixed size Up: Fixed size matrices Previous: Fixed size matrix subtraction Contents

Rescaling a fixed size matrix

There are similar functions to multiply a $3\times 4$ matrix by a scalar

  double ds;

  gan_mat34_scale_q ( &m34A, ds, &m34C ); /* macro */
  m34C = gan_mat34_scale_s ( &m34A, ds ); /* function call */
  gan_mat34_scale_i ( &m34A, ds ); /* macro, result in-place in m34A */

to divide a $3\times 4$ matrix by a (non-zero) scalar

  gan_mat34_divide_q ( &m34A, ds, &m34C ); /* macro */
  m34C = gan_mat34_divide_s ( &m34A, ds ); /* function call */
  gan_mat34_divide_i ( &m34A, ds ); /* macro, result in-place in m34A */

to negate a $3\times 4$ matrix

  gan_mat34_negate_q ( &m34A, &m34C ); /* macro */
  m34C = gan_mat34_negate_s ( &m34A ); /* function call */
  gan_mat34_negate_i ( &m34A ); /* macro, result in-place in m34A */

and to scale a $3\times 4$ matrix to unit unit Frobenius norm

  gan_mat34_unit_q ( &m34A, &m34C ); /* macro */
  m34C = gan_mat34_unit_s ( &m34A ); /* function call */
  gan_mat34_unit_i ( &m34A ); /* macro, result in-place in m34A */

The Frobenius norm of a matrix is the square-root of the sum of squares of the matrix elements. The Gandalf functions for computing it are described in 3.1.2.11.

Equivalent routiness to the above for multiplying/dividing a matrix by a scalar, negating a matrix and scaling a matrix to unit Frobenius norm are available for square fixed size matrices. Without listing the routines exhaustively, some examples are

  gan_mat33_scale_q ( &m33A, ds, &m33C ); /* macro */
  sm33Sc = gan_symmat33_divide_s ( &sm33Sa, ds ); /* function call */
  gan_ltmat33_negate_i ( &sm33La ); /* macro, result in-place in sm33La */
  m33C = gan_mat33_unit_s ( &m33A ); /* function call */

Error detection: If zero is passed as the scalar value to the..._divide_[qi]() routines, NULL will be returned, while the..._divide_s() routines will abort the program. You should add tests for division by zero before calling any of the ..._divide_[qsi]()routines. Similarly, the ..._unit_[qsi]() routines will fail if the input matrix contains only zeros. If this is a possibility then the program should check beforehand.


next up previous contents
Next: Transposing a fixed size Up: Fixed size matrices Previous: Fixed size matrix subtraction Contents

2006-03-17