[ESS] [R] How to get correct integration in C for step function?
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Mon Jan 22 02:26:22 CET 2007
Hi, Lynette,
A few pointers:
1. Not an R question.
2. Not an ESS question.
3. No reproducible example.
4. (x >= 1/4) is comparing a pointer. Surely, this is not what you
intended to do. Plus, if you're using void* then this is not even a C
function called by R. And I'm not familiar with Rdqags.
5. Please use the posting guide in the future.
http://www.R-project.org/posting-guide.html
HTH,
--sundar
Lynette said the following on 1/21/2007 5:24 PM:
> Dear all,
>
> I am using Rdqags in C to realize the integration. It seems for the
> continous C function I can get correct results. However, for step functions,
> the results are not correct. For example, the following one, when integrated
> from 0 to 1 gives 1 instead of the correct 1.5
>
> void func( double *x, int n, void *ex )
> {
> int i;
>
> for(i=0;i<n;i++) { x[i]=( ((x>=1/4)&&(x<=3/4)) ? 2:1 ) ; }
> return;
> }
>
> while the following one when integrated from 0 to 1 gives the correct
> 0.7853983
>
> void func( double *x, int n, void *ex )
> {
> int i;
>
> for(i=0;i<n;i++) { x[i]= pow(1-x[i]*x[i],.5); }
> return;
> }
>
> Please advise the problems. Thanks a lot.
>
> Best,
> Lynette
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
More information about the ESS-help
mailing list