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?
f
get mixed up with the later arguments of the same. You could definef
using\[FormalX]
and\[FormalY]
as integration variables in order to avoid trouble. $\endgroup$Block
to scope their variables. I'm lazy though, so I go forxx
andyy
when I can't usex
andy
$\endgroup$x,y
toxx,yy
as @JasonB suggested, and now instead of outputting the errors it's running... and running... and still running... :-) $\endgroup$ClearAll[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 $\endgroup$y
can be done analytically (Integrate
), then you are left with a much faster 1-dNIntegrate
over x. $\endgroup$