comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: plot dirac delta function?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: plot dirac delta function? [message #49355] Wed, 19 July 2006 12:20 Go to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Benjamin Hornberger wrote:
> kuyper@wizard.net wrote:
>>
>> The Dirac delta function is defined by the following equations:
>>
>> delta(x) = 0 if x ne 0
>>
>> integral of delta(x) dx from x0 to x1 = 1, if x0 < 0 and x1 > 0
>>
>> Notice that this definition fails to identify explicitly the value of
>> delta(0). That's because there's no meaningful value that can be
>> assigned to delta(0). The best you can do is to call it infinity, but
>> even that's not quite right, for reasons that I don't remember right
>> now.
>
> I think that (the last paragraph) applies to the continuous case. In the
> discrete case, it follows quite clearly from the two equations above
> that the delta function must be an array which is 1 for the center (more
> on that below) and zero otherwise. Two examples:

In my experience, the term "Dirac delta function" is restricted to what
you call the continuous case. The corresponding thing for the discrete
case is referred to as the Kroenecker delta. See, for example,
< http://www.physics.umd.edu/courses/Phys374/fall04/hw/MP27.ht m>.

I think it's even less meaningful (though much easier!) to plot the
kroenecker delta than the Dirac delta function. It's only defined on a
discrete set of points, so drawing lines between the consecutive points
of the plot would be inappropriate.
Re: plot dirac delta function? [message #49359 is a reply to message #49355] Wed, 19 July 2006 09:28 Go to previous messageGo to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
kuyper@wizard.net wrote:
>
> The Dirac delta function is defined by the following equations:
>
> delta(x) = 0 if x ne 0
>
> integral of delta(x) dx from x0 to x1 = 1, if x0 < 0 and x1 > 0
>
> Notice that this definition fails to identify explicitly the value of
> delta(0). That's because there's no meaningful value that can be
> assigned to delta(0). The best you can do is to call it infinity, but
> even that's not quite right, for reasons that I don't remember right
> now.

I think that (the last paragraph) applies to the continuous case. In the
discrete case, it follows quite clearly from the two equations above
that the delta function must be an array which is 1 for the center (more
on that below) and zero otherwise. Two examples:

1. Convolution of a function (array) with a delta function must
reproduce the function (or shift if the delta function is not centered).
This is clearly fulfilled by an array which has a 1 in one element and
zeroes otherwise.

2. The Fourier Transform of a (centered) delta function is a constant.
The value of the constant depends somewhat on the definition of the FT
(in IDL, the forward FFT of a delta function as defined above is a
constant 1/N, N being the number of array elements, and the reverse FFT
is a constant 1).

You have to keep in mind that for frequency analysis, IDL assumes the
zero frequency ("center") to be at the zero element in real AND Fourier
space. I, like many others, prefer to shift all arrays by minus/plus N/2
before and after an FT and work on "centered" arrays, which makes the
plots look more intuitive.
Re: plot dirac delta function? [message #49360 is a reply to message #49359] Wed, 19 July 2006 08:31 Go to previous messageGo to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Nic wrote:
> Hi all!
>
> I am new to IDL and learning how to do non analytic plots such as a
> dirac delta function or a finite square well. Does anybody have ideas
> of what tools I should use or keywords to get started in plotting
> these?
>
> thank you

The Dirac delta function is defined by the following equations:

delta(x) = 0 if x ne 0

integral of delta(x) dx from x0 to x1 = 1, if x0 < 0 and x1 > 0

Notice that this definition fails to identify explicitly the value of
delta(0). That's because there's no meaningful value that can be
assigned to delta(0). The best you can do is to call it infinity, but
even that's not quite right, for reasons that I don't remember right
now.
Conceptually, you can consider delta(x) to be a member of a family of
functions delta(x,e), with the following properties:

delta_e(x,e) =0 for x<=-e or x>=e
delta_e(0,e) = 1/e
delta_e(x,e) is linear for -e<=x<=0, and for 0<=x<=e

With this definition, you can think of delta(x) as the limit, as e->0,
of delta_e(x,e); except that this limit is not well-defined.

What you need to do to make an expression containing a delta function
meaningfull is to integrate it. For instance:

integral f(x)*delta(a*(x-x1)) dx from x0 to x2 =
f(x1)/a if x0<x1<x2
0 if x1<x0<x2 or x0<x2<x1

Therfore, it's rather meaningless to try to plot the Dirac delta
function itself. If, however, you insist on doing so, you need to scale
the y axis so that it maps an infinite range of values into a finite
range on your screen. One simple transformation with this property is
y=logit(norm), where norm is a value that runs from 0 to 1, and
logit(norm) = alog(norm/(1-norm)). You can implement this in IDL by
defining a function to be used as a YTICKFORMAT option of a PLOT
command:

FUNCTION logit_format, axis, index, value
IF(value LE 0) THEN RETURN, '-INFINITY';
IF(value GE 1.0) THEN RETURN, '+INFINITY'
RETURN, STRING(alog(value/(1-value)), FORMAT='(G9.3)')
END

The Dirac delta function is almost never used without shifting it's
center. Let x0 be the shifted center, and let xmin and xmax be the
domain over which you wish to plot delta(x-x0). Then the following
commands will plot it "sort of" correctly:

PLOT, [xmin, x0, x0, x0, xmax], [0.5, 0.5, 1.0, 0.5, 0.5],
YTICKFORMAT='logit_format'

If you want to plot another function f(x) with the same scaling, you
must rescale the y values, as follows:

OPLOT, x, exp(f(x))/(1+exp(f(x)))

The Heaviside step function is much simpler. It's defined as:

H(x) = 0 for x<0
H(0) = 0.5
H(x) = 1.0 for x>0

It's almost never used without scaling and offsets, so I'll show how to
plot y1*H(x-x0)+y0:

PLOT, [xmin, x0, x0, x0, xmax], [y0, y0, 0.5*(y0+y1), y1, y1]
Re: plot dirac delta function? [message #49364 is a reply to message #49360] Wed, 19 July 2006 04:52 Go to previous messageGo to next message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
here's your discrete delta function:

x=fltarr(100)
x[50]=0.01
plot,x,psym=10

if you want a step function, do instead
x[50:99]=1


Ciao,
Paolo

Nic wrote:
> Hi all!
>
> I am new to IDL and learning how to do non analytic plots such as a
> dirac delta function or a finite square well. Does anybody have ideas
> of what tools I should use or keywords to get started in plotting
> these?
>
> thank you
>
Re: plot dirac delta function? [message #49407 is a reply to message #49360] Sun, 23 July 2006 17:54 Go to previous message
swingnut is currently offline  swingnut
Messages: 30
Registered: September 2005
Member
FYI, while the definition can be approached a number of equivalent
ways, the value of the Dirac IS "well-defined" at delta(x).
Technically, it's "well-defined" at the value such that its argument is
zero (which here is x=0).

The value is indeed infinity. At least, that's how it's used in
physics.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Irregular grid -> 2D binned
Next Topic: Re: LINUX IDL Install Help

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:46:20 PDT 2025

Total time taken to generate the page: 0.00703 seconds