[R] MATLAB vrs. R

Alain Guillet alain.guillet at uclouvain.be
Mon Oct 11 09:59:17 CEST 2010


  Hi,

The first argument of myquadrature in result shouldn't be val but f I 
guess. At least it works for me

 > result=myquadrature(f,0,2000)
 > print(result)
[1] 30000

Regards,
Alain


On 11-Oct-10 09:37, Craig O'Connell wrote:
> Thank you Peter.  That is very much helpful.  If you don't mind, I continued running the code to attempt to get my answer and I continue to get inf inf inf....... (printed around 100 times).
>
> Any assistance with this issue.  Here is my code (including your corrections):
>
>
> myquadrature<-function(f,a,b){
> npts=length(f)
> nint=npts-1
> if(npts<=1)
> error('need at least two points to integrate')
> end;
> if(b<=a)
> error('something wrong with the interval, b should be greater than a')
> else
> dx=b/real(nint)
> end;
> npts=length(f)
> int=0
> int<- sum(f[-npts]+f[-1])/2*dx
> }
>
> #Call my quadrature
> x=seq(0,2000,10)
> h = 10.*(cos(((2*pi)/2000)*(x-mean(x)))+1)
> u = 1.*(cos(((2*pi)/2000)*(x-mean(x)))+1)
> a = x[1]
> b = x[length(x)]
> plot(x,-h)
> a = x[1];
> b = x[length(x)];
> #call your quadrature function.  Hint, the answer should be 30000.
> f=u*h;
> val =  myquadrature(f,a,b); ?  ___________This is where issue arises.
> result=myquadrature(val,0,2000)  ?
> print(result)               ?
>
>
> Thanks again,
>
> Phil
>
>
>   		 	   		
> 	[[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.
>

-- 
Alain Guillet
Statistician and Computer Scientist

SMCS - IMMAQ - Université catholique de Louvain
Bureau c.316
Voie du Roman Pays, 20
B-1348 Louvain-la-Neuve
Belgium

tel: +32 10 47 30 50



More information about the R-help mailing list