s-news
[Top] [All Lists]

Re: (corrected) Double integration(summary)

To: "Dr. Takashi Kikuchi" <takashi.kikuchi@st-hughs.oxford.ac.uk>
Subject: Re: (corrected) Double integration(summary)
From: "Steven C. Wofsy" <scw@io.harvard.edu>
Date: Wed, 27 Jun 2001 17:06:49 -0400
Cc: <s-news@wubios.wustl.edu>
In-reply-to: <003001c0ff47$7bd82e60$a6e501a3@ox.ac.uk>
Reply-to: <Steven_Wofsy@harvard.edu>
There were several typos in the Monte Carlo and Riemann summ file I sent
to the questioner, here are teh correct files.  I think one of the other
responders switched the limits for x and y ...

#2-dimensional Monte Carlo integration
#flexible, fast, slow to converge, gives good approx answer
M<-900000 # points
rangex<-c(2,3)
rangey<-c(1,5)
f<-function(x,y){20/(x*y^2)}
fint<-mean(f(runif(M,rangex[1],rangex[2]),runif(M,rangey[1],rangey[2])))*
       diff(rangex)*diff(rangey)
2-d Riemann sums
N=500
xx<-seq(from=2,to=3,length=N)
yy<-seq(from=1,to=5,length=N)
int2<-0
for(yz in yy){
int2<-int2+sum(f(xx,yz ) )

}
int2.x<-int2*diff(rangex)*diff(rangey)/N^2

Steven C. Wofsy
Abbott Lawrence Rotch Professor of Atmospheric and Environmental Chemistry
Harvard University
Pierce Hall, Room 110D, 29 Oxford St., Cambridge, MA 02138
email:  Steven_Wofsy@harvard.edu
Telephone:  617-495-4566  FAX: 617:495-4551




<Prev in Thread] Current Thread [Next in Thread>