Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Plot DiracDelta[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28513] RE: [mg28465] Plot DiracDelta[]
  • From: "David Park" <djmp at earthlink.net>
  • Date: Tue, 24 Apr 2001 01:48:49 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Max,

I think what you really wanted is a routine that will recognize DiracDeltas
and plot them. Here is a routine that should work for most ordinary uses.
DrawingPaper has a routine DrawUnitStep which will draw UnitStep expressions
without the jump lines. I plan to eventually replace it with the following
routine which also plots DiracDeltas as labeled arrows. The version given
here is standalone and can be used without DrawingPaper.

Needs["Graphics`Arrow`"]
Needs["Graphics`Colors`"]
Needs["Utilities`FilterOptions`"]

ClearAll[DrawUnitStep2];
DrawUnitStep2::usage = "DrawUnitStep2[expr, {x, xmin, xmax}, options...]
will \
plot expressions which contain (f[x] UnitStep[x-a]) and (f[x] \
DiracDelta[x-a]) or which can be expanded into a sum of such terms. UnitStep
\
functions are drawn without the jump lines. The Dirac deltas are drawn as \
constant length arrows. The option DDeltaScale (default 1) specifies the \
length of the arrow. The option DDeltaColor (default Black) specifies the \
color of the arrows. The arrows are labeled at their midpoints with the
value \
of the Dirac delta. The option DDNumberFormat (default (#&)) can be used to
\
specify the formatting of the labels. Options can also be passed to the Plot
\
and Arrow routines.";
Options[DrawUnitStep2] = {DDeltaScale -> 1, DDeltaColor -> Black,
    DDNumberFormat -> (#1 & )};
DrawUnitStep2[expr_, {x_, min_, max_}, (opts___)?OptionQ] :=
  Module[{usbreaks, dddata, expr2, usroot, extractdddata, curves, arrows,
    plotopts, arrowopts, ddscale, ddcolor, ddnumformat, loc, value},
   ddscale = DDeltaScale /. {opts} /. Options[DrawUnitStep2];
    ddcolor = DDeltaColor /. {opts} /. Options[DrawUnitStep2];
    ddnumformat = DDNumberFormat /. {opts} /. Options[DrawUnitStep2];
    plotopts = FilterOptions[Plot, opts];
    arrowopts = FilterOptions[Arrow, opts]; usroot[e_] :=
     Solve[e == 0, x][[1,1,2]]; getdddata[a_, b_] :=
     Module[{loc, value}, loc = usroot[b]; value = a/Abs[D[b, x]] /.
         x -> loc; {loc, value}];
    expr2 = Expand[FunctionExpand[Simplify[expr]]];
    usbreaks = Union[Cases[expr2, UnitStep[a_] :> usroot[a], {0,
Infinity}]];
    usbreaks = Join[{min}, Select[usbreaks, #1 > min && #1 < max & ],
{max}];
    dddata = Cases[expr2, (a_.)*DiracDelta[b_] :> getdddata[a, b], {0, 1}];
    expr2 = expr2 /. DiracDelta[__] -> 0;
    curves = MapThread[First[Plot[expr2, {x, #1, #2}, Evaluate[plotopts],
         DisplayFunction -> Identity]] & , {Drop[usbreaks, -1],
       Drop[usbreaks, 1]}]; arrows =
     ({loc = #1[[1]]; value = #1[[2]]; Arrow[{loc, expr2 /. x -> loc},
          {loc, (expr2 /. x -> loc) + Sign[value]*ddscale},
          Evaluate[arrowopts]], Black, Text[ddnumformat[value],
         {loc, (expr2 /. x -> loc) + Sign[value]*(ddscale/2)},
         {-1, 0}]} & ) /@ dddata; {curves, {ddcolor, arrows}}]

A sample plot.

f3[x_] := Cos[x]*(UnitStep[x] - UnitStep[x - Pi]) +
   Sin[x]*(DiracDelta[x - Pi/4] - DiracDelta[x - 3*(Pi/4)])

Show[Graphics[DrawUnitStep2[f3[x], {x, -Pi, 2*Pi}, HeadCenter -> 1/2,
     DDNumberFormat -> (StyleForm[DisplayForm[FrameBox[NumberForm[N[#1],
           2]]], Background -> LightBlue, FontSize -> 8] & )]],
   Frame -> True, FrameLabel -> {x, HoldForm[f3[x]]},
   PlotLabel -> "Sample DiracDelta Plot", ImageSize -> 500,
   PlotRange -> All];

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

> From: Max Ulbrich [mailto:ulbrich at biochem.mpg.de]
To: mathgroup at smc.vnet.net
> Hi,
>
> does anybody know if there is a possibility
> to include the DiracDelta[] in a Plot?
> If I have
>
> Plot[DiracDelta[x-1],{x,0,2}]
>
> I see nothing, but I would like to see
> a vertical line at x=1.
>
> Max
>
>



  • Prev by Date: RE: Two questions concerning ListDensityPlot ...
  • Next by Date: Re: Help on solving simultaneous non-linear equations using FindRoot.
  • Previous by thread: Re: Plot DiracDelta[]
  • Next by thread: CreateHyperlinkDialog