Learn R Programming

RcppGSL (version 0.3.0)

colNorm: Column norm of a matrix

Description

colNorm provides a column norm of a matrix to provide an example of using RcppGSL with GNU GSL library.

Usage

colNorm(M)

Arguments

M
a numeric matrix.

Value

  • colNorm returns a vector each element of which corresponds to the vector norm of the corresponding column of M.

Details

The column norm of M is returned.

This example reprises an example in section 8.4.13 of the GSL reference manual.

References

GNU GSL project: http://www.gnu.org/software/gsl

Examples

Run this code
## see Section 8.4.13 of the GSL manual
  ## create M as a sum of two outer products
  M <- outer(sin(0:9), rep(1,10), "*") + outer(rep(1, 10), cos(0:9), "*")
  print(colNorm(M))
  ## same result using just R
  print(apply(M, 2, function(x) sqrt(sum(x^2))))

Run the code above in your browser using DataLab