Hi all,

Why 

fr2<-function(x)
{ if(x<1){x*x}else{1}
}

 integrate(fr2,-1,2) 

gives the following wrong answer:

3 with absolute error < 3.3e-14
Warning message: 
the condition has length > 1 and only the first element will be used in: if (x < 1) { 

while

fr<-function(x){as.numeric(x<1)*(x^2-1)+1}

 integrate(fr,-1,2)    

works?

1.666667 with absolute error < 3.4e-05

Thanks.


Lynette Sun

Department of Statistics

	[[alternative HTML version deleted]]


