[R] computing functions with Euler's number (e^n)

Daniel Malter daniel at umd.edu
Sat Jul 9 03:27:19 CEST 2011


The problem arises in the computation of U where (-dummy+1) turns negative
(the eighth and higher index values of "dummy"). You raise a negative number
to a non-integer power, for example, (-pi)^exp(1), which fails because you
would not be able to tell, which sign the resulting number should have.
Generally, non-integer powers of negative numbers are only defined in a
specific subset of cases.

(-dummy[8]+1)^B[1]
[1] NaN

HTH,
Daniel


William Armstrong-2 wrote:
> 
> I am trying to create a set of wavelets in frequency space--namely Cauchy
> wavelets for an intensity analysis (von Tscharner, 2000).  The wavelets
> are
> defined by the following formula:
> 
> [(f/cf)^(cf*scale)]*[e^((-f/cf)+1)^(cf*scale)]
> 
> where *f *is frequency of length *n*, *cf* is center frequency (defined
> below) and is an array of *j *columns and *n* row, and scale is a
> constant.
> 
> cf = (1/scale)*(j + q)^r
> where *j *is the number of center frequencies (i.e., columns), and *q* and
> *
> r* are constants.
> 
> When I get to Q, the output returns numbers only up to cf.  Beyond cf, Q
> and
> subsequently W return "NA." I understand this is because when fq >/=  cf 
> U
> becomes zero^B[j] or a negative^B[j].  From here, Q should equal 1/exp(U)
> to
> compute W.  I know that I need to create a loop here, but as a newbie to
> R,
> I don't know how to write the correct loop that will work for me.  Any
> suggestions??
> 
> 
> 
> Here is the code I have been using (less the numerous if...else attempts):
> 
> 
> 
>> J <- 12
> 
>> r_ <- 1.959
> 
>> q_ <- 1.45
> 
>> scale_ <- 0.3
> 
>> N <- 500
> 
>> fq <- seq(0, N, 1)
> 
>> center_frequencies <- function(J = 12, r_ = 1.959, q_ = 1.45, scale_ =
> 0.3){
> 
> + j <- seq(0,J-1,1)
> 
> + fc <- (q_ + j)^r_/scale_
> 
> + }
> 
>> fc <- center_frequencies(12,r_,q_,scale_)
> 
>> cf <- t(fc)
> 
>> lambda <- function(cf, J = 12, scale_ = 0.3){
> 
> + B <- cf*scale_
> 
> + }
> 
>> B <- lambda(cf, 12, 0.3)
> 
>> dummy <- fq/cf[1]
> 
>> Z <- dummy**B[1] # Note here I tried using '^' to raise dummy to the
>> power
> B[j], but it didn't work.  I tried '**' which serves the same purpose in
> LabVIEW, and it worked.  There is no references to this in any of the R
> documentation that I have read.  Should '^' work here???
> 
>> U <- (-dummy+1)**B[1]
> 
>> Q <- exp(U)
> 
>> Q <- ifelse(Q>30,30,Q)  # Not sure why I use this.
> 
>> W <- Z*Q
> 
> 
> -- 
> *W. Jeffrey Armstrong, Ph.D.
> *Assistant Professor
> Exercise Science
> 
> *Managing Editor
> Clinical Kinesiology*
> Official Journal of the American Kinesiotherapy Association
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

--
View this message in context: http://r.789695.n4.nabble.com/computing-functions-with-Euler-s-number-e-n-tp3655205p3655505.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list