yingfu xie
2012-May-08 11:02 UTC
[R] Numerical integration of a two dimensional function over a disk
Hello, there! Basically my problem is very clear. I would like to take a (numerical) integration of a function f(x,y) which can be quite complex of x and y, over a disk (x-a)^2+(y-b)^2<= r^2 (with r constant). However, after some search in R, I just cannot find a function in R that suits my purpose. Function Integrate applies to one dimensional, and adaptIntegrate to rectangle. In my case, it is not easy or simply impossible to transform the definition area to a rectangle with constant boundaries. I must have missed something, but is there any R function which can solve the integration without going to ex. Monto Carlo? Many thanks in advance! Best regards, Yingfu [[alternative HTML version deleted]]
Jeff Newmiller
2012-May-08 11:44 UTC
[R] Numerical integration of a two dimensional function over a disk
"Simply impossible" seems an odd description for a technique described in every elementary calculus text under the heading "integration in cylindrical coordinates". --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. yingfu xie <xieyingfu at yahoo.com> wrote:>Hello, there! >? >Basically my problem is very clear. I would like to take a >(numerical)?integration of a function f(x,y) which can be quite complex >of x and y, over a disk (x-a)^2+(y-b)^2<= r^2 (with r constant). >However, after some search in R, I just cannot find a function in R >that suits my purpose. Function Integrate applies to one dimensional, >and adaptIntegrate to?rectangle. In my case, it is not easy or >simply?impossible?to transform?the definition area?to a rectangle with >constant?boundaries. ??I must have missed something, but is there any R >function which can solve the integration without going to ex. Monto >Carlo? Many thanks in advance! >? >Best regards, >Yingfu > [[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.
...still new to R and trying to figure this one out. I have a number of variables x, y, z, etc. in a data frame. Each contains a 2 digit year (e.g., 80, 81, 82) representing the first year that something occurred. Each variable represents a different type of event. If the event did not occur at all, the variable has the value 0 (zero). I need to create a new variable having the value of the earliest year among the set of variables. If none of the events occurred (all variables = 0), then the new variable should also be zero. e.g., Original x y z 80 82 83 85 76 90 90 0 86 0 0 0 New variable 80 76 86 0
On Tue, May 08, 2012 at 02:50:47PM -0500, Jeff wrote:> > ...still new to R and trying to figure this one out. > > I have a number of variables x, y, z, etc. in a data frame. > > Each contains a 2 digit year (e.g., 80, 81, 82) representing the > first year that something occurred. Each variable represents a > different type of event. > > If the event did not occur at all, the variable has the value 0 (zero). > > I need to create a new variable having the value of the earliest year > among the set of variables. > > If none of the events occurred (all variables = 0), then the new > variable should also be zero. > > e.g., > > Original > x y z > 80 82 83 > 85 76 90 > 90 0 86 > 0 0 0 > > > New variable > 80 > 76 > 86 > 0Hi. If all years are at most 99, then try the following dat <- data.frame(x=c(80, 85, 90, 0), y=c(82, 76, 0, 0), z=c(83, 90, 86, 0)) dat[dat == 0] <- Inf out <- pmin(dat$x, dat$y, dat$z) out[out == Inf] <- 0 out [1] 80 76 86 0 Hope this helps. Petr Savicky.