Created
July 3, 2016 23:07
-
-
Save raffitz/0ac61c3b38b59463c91462eed80c32a5 to your computer and use it in GitHub Desktop.
Quadruple integral to calculate average distance between two random points within a unit square
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Matlab script to determine average distance between two random points within a unit square | |
f=@(x,y,z,w) sqrt((x-z).*(x-z) + (y-w).*(y-w)); % Distance Function between points (x,y) and (z,w) | |
a=0.5;b=0.5;c=0.5;d=0.5; % Integration limits: -a<=x<a -b<=y<b -c<=z<c -d<=w<d | |
I=integral2(@(x,y)arrayfun(@(x,y)integral2(@(z,w)f(x,y,z,w),-c,c,-d,d),x,y),-a,a,-b,b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit to Daniel F here: https://stackoverflow.com/questions/25141102/quadruple-integral-using-nested-integral2-in-matlab