I am trying to visualize diffusion distribution from an equilateral triangle with 45 degrees. Assuming that diffusion is a Gaussian with sigma=1 this should do:
f[a_, b_, c_] := Integrate[E^(-x^2 - y^2), {x, -a, -a + c}, {y, -b, x - b + a}] / Pi
where {a,b} are the coordinates and c is the size of the triangle's side.
A quick sanity check seems reasonable:
f[0, 0, 10] // N
returns 0.125 as expected.
However, this command:
Plot3D[f[x, y, 10], {x, -3, 13}, {y, -3, 13}]
generates these errors:
Integrate::ilim: "Invalid integration variable or limit(s) in {-2.998856`,2.998856`,12.998856`}"
NIntegrate::dupv: "Duplicate variable -2.99886 found in NIntegrate[1.54405*10^-8,{-2.99886,2.99886,12.9989},{-2.99886,2.99886,-2.99886}]."
Integrate::ilim: Invalid integration variable or limit(s) in {-1.856,1.856,11.856}.
NIntegrate::itraw: "Raw object -1.856 cannot be used as an iterator."
Could you tell what I'm doing wrong here?
fget mixed up with the later arguments of the same. You could definefusing\[FormalX]and\[FormalY]as integration variables in order to avoid trouble. – b.gates.you.know.what Aug 24 '16 at 16:48probablyright here, since the plotting functions all useBlockto scope their variables. I'm lazy though, so I go forxxandyywhen I can't usexandy– Jason B. Aug 24 '16 at 16:50x,ytoxx,yyas @JasonB suggested, and now instead of outputting the errors it's running... and running... and still running... :-) – Michael Aug 24 '16 at 17:04ClearAll[f]; f[a_?NumericQ, b_?NumericQ, c_?NumericQ] := NIntegrate[E^(-x^2 - y^2), {x, -a, -a + c}, {y, -b, x - b + a}]/Pi, plots in a little under a minute – Jason B. Aug 24 '16 at 17:15ycan be done analytically (Integrate), then you are left with a much faster 1-dNIntegrateover x. – george2079 Aug 24 '16 at 19:26