Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Plotting piecewise in 2D

72 views
Skip to first unread message

Jim Lambaugh

unread,
May 14, 2010, 5:32:49 AM5/14/10
to
Hi

Please take a look at

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

This just gives me a uniform plot. Why does the peak at (0,0) not show
up?

Best,
Jimmy.

Patrick Scheibe

unread,
May 14, 2010, 7:57:50 PM5/14/10
to
Hi,

because at the end all comes to the point that your function is sampled
at different places and single dicontinuous points are a problem

DensityPlot[
Piecewise[{{1000, x == 0 && y == 0}}, 0], {x, -1, 1}, {y, -1, 1},
PlotPoints -> 3, Mesh -> All, MaxRecursion -> #,
ColorFunction -> "LightTemperatureMap"] & /@ Range[1, 10]

Such stuff will not work reliable. Try to sample it by yourself and see
what happens

ArrayPlot[
Table[If[x == 0 && y == 0, 1000, 0], {y, -1, 1, 2/#}, {x, -1, 1,
2/#}]] & /@ Range[50, 55]

Cheers
Patrick

Bob Hanlon

unread,
May 14, 2010, 7:58:00 PM5/14/10
to

Because it is hard to see a point?

However, the following shows an excessively large area:

DensityPlot[
If[Abs[x] < 0.001 && Abs[y] < 0.001, 1000, 0],


{x, -1, 1}, {y, -1, 1}]

"If" is a programming construct not a mathematical function. Piecewise works better.

DensityPlot[
Piecewise[{{1000, Abs[x] < 0.001 && Abs[y] < 0.001}}],
{x, -1, 1}, {y, -1, 1}]


Bob Hanlon

---- Jim Lambaugh <lamb...@gmail.com> wrote:

=============

Peter Pein

unread,
May 14, 2010, 7:58:33 PM5/14/10
to
Am Fri, 14 May 2010 09:32:49 +0000 (UTC)
schrieb Jim Lambaugh <lamb...@gmail.com>:

Because a point is too small for the real world ;-)

Try:
DensityPlot[If[Norm[{x, y}] <= 1*^-9, 1000, 0], {x, -1, 1}, {y, -1, 1}]

hth,
Peter


Bill Rowe

unread,
May 15, 2010, 6:14:26 AM5/15/10
to
On 5/14/10 at 5:32 AM, lamb...@gmail.com (Jim Lambaugh) wrote:

>Please take a look at

>DensityPlot[If[x == 0 && y == 0, 1000, 0], {x, -1, 1}, {y, -1, 1}]

>This just gives me a uniform plot. Why does the peak at (0,0) not
>show up?

There are a variety of issues. First, the plot routines in
Mathematica (or any software for that matter) obviously cannot
sample your function at all possible points since it is defined
for all real values of x, y. And unless your function is sampled
at {0,0} the output is a constant resulting in a uniform plot.

Next, even if your function were sampled at {0,0} you likely
would still see an uniform plot. By default, Mathematica scales
plots to show what it considers the interesting portion of the
plot. This results in a scaling that will not show one extreme
point. As a simple example, try the following:

data = Join[RandomReal[1, {100}], {1000}, RandomReal[1, {100}]];
ListPlot[data]
ListPlot[data,PlotRange->All]

The first plot will not show the single extreme data point at
1000. The second plot will show the extreme but loses all detail
shown by the first plot in the bulk of the data.

=46inally, even if the sampling included the value at {0,0} and
the plot were scaled correctly to display the function value, it
still might not be apparent in the plot. Depending on other
factors such as plot size, plot resolution etc., it might be
possible the value at {0,0} is represented by a single pixel on
your display. Since it would be surrounded by many pixels with
different values, the single pixel might well be effectively invisible.


0 new messages