R/Mnorm.R

Defines functions Mnorm

Documented in Mnorm

Mnorm <-
function(X, k=2)
  {
### the norm function in matlab
##  returns the largest singular value of the matrix or vector
##  here we create a function to duplicate this bizare behavior
    if(missing(k))  k=2

    if(k==1)
      {
        if(is.matrix(X))
          {
            s1 = apply(abs(X), 2, sum)
            return(max(s1))
          }
        else
          {

            s = sum(abs(X))
             return(s)
          }
            
      }

    if(is.matrix(X))
      {
        s = svd(X, 0, 0)
        return(max(s$d))
      }
    else
      {
       s = sqrt(sum(X^2))
       return(s)
      }
    
   

  }

Try the PEIP package in your browser

Any scripts or data that you put into this service are public.

PEIP documentation built on Aug. 21, 2023, 9:10 a.m.