MathGroup Archive 2000

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

Search the Archive

Re: Complex Function Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25574] Re: [mg25541] Complex Function Plot
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Sun, 8 Oct 2000 00:42:00 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

You might use ComplexExpand with the TargetFunctions -> {Re, Im}. I'm 
not sure this will take less time than twice evaluating f[t]; it surely 
depends on the form of f. For example, in a simple case:

In[1]:=
f[t_] := Exp[I  t^2]

Now you evaluate f[t] twice to produce the Real and Imaginary parts:

In[2]:=
Simplify[f[t] // Re, t \[Element] Reals]
Out[2]=
Cos[t^2]
In[3]:=
Simplify[f[t] // Im, t \[Element] Reals]
Out[3]=
Sin[t^2]

Here you evaluate f[t] only once:

In[4]:=
ComplexExpand[f[t], TargetFunctions -> {Re, Im}]
Out[4]=
Cos[t\^2] + ImaginaryI]\ Sin[t\^2]\)

However, it takes slightly more to evaluate the latter. In 10,000 
evaluations of each case I obtain the following results:

In[8]:=
Table[Simplify[f[t] // Re, t \[Element] Reals], {t, 0, 10, 0.001}]; // 
Timing
Out[8]=
{6.59 Second, Null}
In[9]:=
Table[Simplify[f[t] // Im, t \[Element] Reals], {t, 0, 10, 0.001}]; // 
Timing
Out[9]=
{6.53 Second, Null}
In[10]:=
Table[ComplexExpand[f[t], TargetFunctions -> {Re, Im}], {t, 0, 10,
        0.001}]; // Timing
Out[10]=
{15.27 Second, Null}

I guess you'd have to experiment a little. Hope this helps.

Tomas Garza
Mexico City


"Roberto Brambilla" <rlbrambilla at cesi.it> wrote:

> I have often to plot the real and the imaginary part
> of a complex valued function of a real variable : f(t).
> The obvious solution is
>
> Plot[{f[t]//Re,f[t]//Im},{t,t1,t2},
>       PlotStyle->{Hue[.7],Hue[.9]}]
>
> and the function is evaluated two times for each value of t.
> In the case of a long-time-eating function (as in the case
> of series expansions with hypergeometric f.,integrals with
> parameters,etc) it would be suitable a trick to evaluate
> f[t] only once.
> I'd like also to avoid to use interpolation like
>
> p=Table[f[t1+k(t2-t1)k/n],{k,0,n}];
> fr=Interpolation[p//Re,InterpolationOrder->mr];
> fi=Interpolation[p//Im,InterpolationOrder->mi];
> Plot[{fr[t],fi[t]},{t,t1,t2},
>       PlotStyle->{Hue[.7],Hue[.9]}]
>
> since it requires the optimum choice of n, mr and mi
> for each (t1,t2) interval, especially if the two parts
> oscillate with very different periods.
>
> I use Math. version 3.0 .
> Any suggestion will be greatly appreciated.



  • Prev by Date: Re: RE:? D[f,{x,n}]
  • Next by Date: Re: MultiLinear and Linear function
  • Previous by thread: RE: Complex Function Plot
  • Next by thread: Re: Complex Function Plot