R/weierstrass.R

Defines functions weierstrass

Documented in weierstrass

weierstrass <- function(x, a = 0.5, b = 3, kmax = 20) {
  D <- length(x)
  term1 <- sum(sapply(1:D, function(i) {
    sum(sapply(0:kmax, function(k) {
      a^k * cos(2 * pi * b^k * (x[i] + 0.5))
    }))
  }))
  
  term2 <- D * sum(sapply(0:kmax, function(k) {
    a^k * cos(2 * pi * b^k * 0.5)
  }))
  
  return(term1 - term2)
}

Try the EEEA package in your browser

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

EEEA documentation built on June 10, 2025, 9:13 a.m.