Mathematica Mathematica: Plotting piecewise functions

AI Thread Summary
The discussion centers on the limitations of using DensityPlot for visualizing functions that are non-continuous or defined only at specific points. The primary issue highlighted is that DensityPlot is not effective for functions that are zero everywhere except at a single point, such as the provided example. Additionally, it is noted that functions with jump discontinuities can lead to approximation artifacts, which can be mitigated by adjusting parameters like PlotPoints and MaxRecursion. The conversation emphasizes that DensityPlot is better suited for functions that are at least continuously differentiable (C^1) in the area being plotted. The user acknowledges the feedback and expresses intent to explore the suggestions provided.
Niles
Messages
1,834
Reaction score
0
Hi guys

Take a look at

Code:
DensityPlot[If[x == 0 && y == 0, 1, 0], {x, -1, 1}, {y, -1, 1}]

This just gives me a uniform plot. Why does the peak at the origin not show up?


Niles.
 
Physics news on Phys.org
There are two main reasons why you'll have trouble with attempting to plot functions like that using DensityPlot.

  • The function is zero everywhere but at a single point. DensityPlot[] is unsuitable for functions like this, as a few minutes thought should convince you.
  • Even for other function with jump discontinuities, the number of plot points and the maximum recursion depth you use for DensityPlot[] can have a significant effect on the approximation. For instance, if you try to use

    Code:
    DensityPlot[HeavisideTheta[x, y], {x, -1, 1}, {y, -1, 1}]

    you'll see that the resulting density plot exhibits approximation artifacts around the jump discontinuity in the 2D Heaviside function. This can be controlled using PlotPoints and MaxRecursion, but you should be aware that DensityPlot[] is more suited to functions that are at least C^1 everywhere in the region of interest.
 
shoehorn said:
There are two main reasons why you'll have trouble with attempting to plot functions like that using DensityPlot.

The function is zero everywhere but at a single point. DensityPlot[] is unsuitable for functions like this, as a few minutes thought should convince you.

You are correct; I need to think a little more. Thanks; I'll try out your suggestions.
 

Similar threads

Replies
1
Views
2K
Replies
4
Views
1K
Replies
13
Views
2K
Replies
5
Views
2K
Replies
5
Views
2K
Replies
1
Views
2K
Back
Top