I am trying to plot a two variable function
A simple function x*DiracDelta(y)+y*DiracDelta(x)
code will work with simple function without DiracDelta But when I enter the delta function, it gives an error?
Can you help me find the problem with this code?
from sympy import symbols, DiracDelta
from sympy.plotting import plot_parametric
from sympy import symbols, DiracDelta
from sympy.plotting import plot3d
x, y = symbols('x y')
f = x*DiracDelta(y)+y*DiracDelta(x)
plot3d(f, (x, -1, 1), (y, -1, 1))
Thanks!
try to plot a 3d function It works when I have function without Delta function but it give me error when put delta function
About DiracDelta in general
The Dirac distribution is not a function in the mathematical sense.
The sympy documentation for sympy.DiracDelta states it explicitly:
So, you can't plot it like a function, because it isn't a function.
In simple words, the Dirac distribution behaves like a function that is 0 almost everywhere, but has an integral of 1 in any interval that includes 0.
Intuitively, if it could be plotted like a function, the Dirac distribution would have a plot that looks kinda like this:
Except the width of the peak should be 0, and the area under the peak should be exactly 1. This of course would be self-contradictory for a function, so no plot will be truly satisfactory. Again, the Dirac distribution is not a function.
About your
f = x*DiracDelta(y)+y*DiracDelta(x)Again, f is not a function in the mathematical sense. It will behave like a function that is 0 almost everywhere, but with an integral equal to
(x2**2 - x1**2)/2on regions that intersect segment [x1, x2] on the x-axis, and an integral equal to(y2**2 - y1**2)/2on regions that intersect segment [y1, y2] on the y-axis.Instead of plotting
f, which won't work sincefis not a function, I suggest approximatingDiracDeltaby a "peak" function like the one I drew above, and plot an approximation offusing this approximation ofDiracDelta. For instance: