Smirk
Smirk

Reputation: 59

integration-get a result of wrong type

My formula is

 $$\int_{a}^{b}\big(exp(x) +1 \big)^{i\cdot u} \cdot \text{cos} \big((x-\alpha) u \big)dx$$  

Here is my R code for integration:

 a<--2; b<-2; u<-0.15; alpha<-0.8

 integrand<-function(x)
{
 (exp(x)+1)^(1i*u)*cos((x-alpha)*u)
}

integrate(integrand,lower=a,upper = b)

After running this code, I got the error message from R:

Error in integrate(integrand, lower = a, upper = b) : 
evaluation of function gave a result of wrong type

Where is my mistake? Thanks!

Upvotes: 1

Views: 92

Answers (1)

AK88
AK88

Reputation: 3026

Apparently, integrate cannot do complex integration. Use elliptic package's myintegrate instead:

 a<-2
 b<-2 
 u<-0.15
 alpha<-0.8

integrand<-function(x) {
   (exp(x)+1)^(1i * u)*cos((x-alpha)*u)
 }

 myintegrate(integrand,lower=a,upper = b)

Upvotes: 1

Related Questions