New Reply

Mathematica: mean of 2d function

 
Share Thread Thread Tools
Jun7-12, 05:29 AM   #1
 

Mathematica: mean of 2d function


Dear all,

I wonder if there is a function implemented in Mathematica to find the average value of a 2d function f(x,y). So averaged over a specified domain.

Thanks in advance for any help!
Sue
 
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Heat-related deaths in Manhattan projected to rise
>> Dire outlook despite global warming 'pause': study
>> Sea level influenced tropical climate during the last ice age
Jun7-12, 11:27 AM   #2
 
If your function is fairly well behaved then perhaps you could integrate over the domain and then divide by the area of the domain.

If you include an example with your posts that is fairly simple, but which when answered would almost certainly be enough to let you understand and solve your actual problem that seems like it usually helps.
 
Jun8-12, 10:50 AM   #3
 
Thanks for the reply!

However, I'm afraid my function is too large for integrating, it just doesn't stop running..
 
Jun8-12, 01:39 PM   #4
 

Mathematica: mean of 2d function


Depending on your function, perhaps you could try using NIntegrate instead of Integrate for your average calculation.

If that doesn't work and your function fairly well behaved and you want to find the average over a fairly simple domain and probably finite domain and not wildly computationally expensive to evaluate then find the mean of the function at 10^3 or 10^6 or 10^8 randomly selected points in the domain.
 
Jun8-12, 02:35 PM   #5
 
NIntegrate indeed does give me an answer, though I get two errors, NIntegrate::slwcon: and NIntegrate::ncvb: so apperently my function is not well behaved.
So I do not think I can use the result as I keep getting the ncvb error also for large nr of recursion..

I don't know how interested you are in my problem..., but here is my function. I need the average value on a small domain [x,-1.5,1.5][y,-.5,.5]

\[Sqrt](((-(7/6) + x)/(2 \[Pi] ((-(7/6) + x)^2 + (-2 + y)^2)) -
x/(\[Pi] (x^2 + (-2 + y)^2)) + (7/6 + x)/(
2 \[Pi] ((7/6 + x)^2 + (-2 + y)^2)) + (-(7/6) + x)/(
2 \[Pi] ((-(7/6) + x)^2 + (-1 + y)^2)) -
x/(\[Pi] (x^2 + (-1 + y)^2)) + (7/6 + x)/(
2 \[Pi] ((7/6 + x)^2 + (-1 + y)^2)) + (-(47/6) + x)/(
2 \[Pi] ((-(47/6) + x)^2 + y^2)) + (-(43/6) + x)/(
2 \[Pi] ((-(43/6) + x)^2 + y^2)) - (-6 +
x)/(\[Pi] ((-6 + x)^2 + y^2)) + (-(29/6) + x)/(
2 \[Pi] ((-(29/6) + x)^2 + y^2)) + (-(25/6) + x)/(
2 \[Pi] ((-(25/6) + x)^2 + y^2)) - (-3 +
x)/(\[Pi] ((-3 + x)^2 + y^2)) + (-(11/6) + x)/(
2 \[Pi] ((-(11/6) + x)^2 + y^2)) + (-(7/6) + x)/(
2 \[Pi] ((-(7/6) + x)^2 + y^2)) - x/(\[Pi] (x^2 + y^2)) + (
7/6 + x)/(2 \[Pi] ((7/6 + x)^2 + y^2)) + (11/6 + x)/(
2 \[Pi] ((11/6 + x)^2 + y^2)) - (
3 + x)/(\[Pi] ((3 + x)^2 + y^2)) + (25/6 + x)/(
2 \[Pi] ((25/6 + x)^2 + y^2)) + (29/6 + x)/(
2 \[Pi] ((29/6 + x)^2 + y^2)) - (
6 + x)/(\[Pi] ((6 + x)^2 + y^2)) + (43/6 + x)/(
2 \[Pi] ((43/6 + x)^2 + y^2)) + (47/6 + x)/(
2 \[Pi] ((47/6 + x)^2 + y^2)) + (-(7/6) + x)/(
2 \[Pi] ((-(7/6) + x)^2 + (1 + y)^2)) -
x/(\[Pi] (x^2 + (1 + y)^2)) + (7/6 + x)/(
2 \[Pi] ((7/6 + x)^2 + (1 + y)^2)) + (-(7/6) + x)/(
2 \[Pi] ((-(7/6) + x)^2 + (2 + y)^2)) -
x/(\[Pi] (x^2 + (2 + y)^2)) + (7/6 + x)/(
2 \[Pi] ((7/6 + x)^2 + (2 + y)^2)))^2 + ((-2 + y)/(
2 \[Pi] ((-(7/6) + x)^2 + (-2 + y)^2)) - (-2 +
y)/(\[Pi] (x^2 + (-2 + y)^2)) + (-2 + y)/(
2 \[Pi] ((7/6 + x)^2 + (-2 + y)^2)) + (-1 + y)/(
2 \[Pi] ((-(7/6) + x)^2 + (-1 + y)^2)) - (-1 +
y)/(\[Pi] (x^2 + (-1 + y)^2)) + (-1 + y)/(
2 \[Pi] ((7/6 + x)^2 + (-1 + y)^2)) + y/(
2 \[Pi] ((-(47/6) + x)^2 + y^2)) + y/(
2 \[Pi] ((-(43/6) + x)^2 + y^2)) - y/(\[Pi] ((-6 + x)^2 + y^2)) +
y/(2 \[Pi] ((-(29/6) + x)^2 + y^2)) + y/(
2 \[Pi] ((-(25/6) + x)^2 + y^2)) - y/(\[Pi] ((-3 + x)^2 + y^2)) +
y/(2 \[Pi] ((-(11/6) + x)^2 + y^2)) + y/(
2 \[Pi] ((-(7/6) + x)^2 + y^2)) - y/(\[Pi] (x^2 + y^2)) + y/(
2 \[Pi] ((7/6 + x)^2 + y^2)) + y/(2 \[Pi] ((11/6 + x)^2 + y^2)) -
y/(\[Pi] ((3 + x)^2 + y^2)) + y/(2 \[Pi] ((25/6 + x)^2 + y^2)) +
y/(2 \[Pi] ((29/6 + x)^2 + y^2)) - y/(\[Pi] ((6 + x)^2 + y^2)) +
y/(2 \[Pi] ((43/6 + x)^2 + y^2)) + y/(
2 \[Pi] ((47/6 + x)^2 + y^2)) + (1 + y)/(
2 \[Pi] ((-(7/6) + x)^2 + (1 + y)^2)) - (
1 + y)/(\[Pi] (x^2 + (1 + y)^2)) + (1 + y)/(
2 \[Pi] ((7/6 + x)^2 + (1 + y)^2)) + (2 + y)/(
2 \[Pi] ((-(7/6) + x)^2 + (2 + y)^2)) - (
2 + y)/(\[Pi] (x^2 + (2 + y)^2)) + (2 + y)/(
2 \[Pi] ((7/6 + x)^2 + (2 + y)^2)))^2)
 
Jun8-12, 03:16 PM   #6
 
Plot3D[yourfunction,{x, -1.5, 1.5}, {y, -.5, .5}]
seems to be fairly well behaved, until you notice that the automated plot range code appears to have clipped off a peak around (0,0).
Plot3D[yourfunction,{x, -1.5, 1.5}, {y, -.5, .5},PlotRange->All]
is amusing and shows a single spike surrounded by a nearly flat plane that indicates you have denominators that go to zero and thus your function goes to infinity. That is going to make an average calculation a little questionable.

Monte Carlo random generation of {x,y} points in your domain and averaging the results over 10^3, 10^4 and 10^5 points gives values of approximately 1.0.

I think that is about the best you are going to do with this
 
Jun8-12, 06:56 PM   #7
 
Recognitions:
Gold Membership Gold Member
I'm not sure if its RIGHT, but with NIntegrate you can specify singularities. I believe yours is at 0,0, so:

AVG = NIntegrate[FF, {x, -3/2, 0, 3/2}, {y, -1/2, 0, 1/2}]/NIntegrate[1, {x, -3/2, 0, 3/2}, {y, -1/2, 0, 1/2}]
I get:
Integrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 18 recursive bisections in x near {x,y} = {1.16666,1.3406*10^-7}. NIntegrate obtained 3.0301 and 6.55317*10^-6 for the integral and error estimates. >>

Which isnt bad, but I dont know if it blows up at higher WorkingPrecision, though I dont think it does. So 3.0301/3 might be your answer? 1.01003.
 
Jun9-12, 04:35 AM   #8
 
Thank you both!

I suppose indeed with a singular point it is difficult to talk about an average value. It is indeed at [0,0].
Why do you divide the integral by NIntegrate[1,{x,-1.5,0,1.5},{y,-0.5,0,0.5}]?
I suppose you’re right as you both obtain an average value of 1..
 
New Reply
Thread Tools


Similar Threads for: Mathematica: mean of 2d function
Thread Forum Replies
Mathematica function help Math & Science Software 9
Mathematica: A function that derives another function on all its arguments Math & Science Software 0
Mathematica play function fun Fun, Photos & Games 0
sum function in mathematica Math & Science Software 2
Give to an interpolation function an analitic function with mathematica Math & Science Software 1