R/fiedler.R

Defines functions fiedler

Documented in fiedler

# fiedler: Fiedler Symmetric matrix ------------------------------------------------

#' @name fiedler
#' @title Create Fiedler matrix
#'
#' @description Fiedler matrix that has a dominant positive eigenvalue and all others are negative
#'
#' @param c N-vector. If \code{c} is a scalar, then returns fiedler(1:c)
#'
#' @return a symmetric dense matrix A with a dominant positive eigenvalue and all others are negative.
#'
#' @export
fiedler <- function(c){
  if (!is.vector(c)){
    stop("'c' is not a vector")
  }
  if(length(c) == 1){
    c <- 1:c
  }
  n <- length(c)
  A <- matrix(raw(), n, n)
  A <- matrix(data = abs(c[col(A)] - c[row(A)]), nrow = n, ncol = n)

  return(A)
}

Try the gallery package in your browser

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

gallery documentation built on Sept. 26, 2024, 5:07 p.m.