Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Plot works in Mathematca 7 but not in Mathematica 8

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115904] Re: Plot works in Mathematca 7 but not in Mathematica 8
  • From: Alexander Elkins <user at compgroups.net/>
  • Date: Tue, 25 Jan 2011 04:21:26 -0500 (EST)
  • References: <ihe47q$qc0$1@smc.vnet.net>

1) One way is to replace (kr + ki I) with k in the expression
and plot Function[k,expression][kr+ki*I] like so:

With[{h=1},
 With[{a=0.0001,kn=Pi/h,kr=3.050},
  Plot[Function[k,
     Abs[(kn^2-k^2)(4h(Log[4h/a]-
           NIntegrate[(1-Exp[I(k)y*Cos[kn*y]])/y,{y,0,2}])+
           I/(k+kn)(Exp[2I(k+kn)h]-1)+
           I/(k-kn)(Exp[2I(k-kn)h]-1))-
         (kn^2+k^2)
           NIntegrate[Exp[I(k)y]Sin[kn*y]/y,{y,0,2}]]][
    kr+ki*I],{ki,-0.23,-0.10}]]]

2) Another way is to notice that
NIntegrate[Exp[I(kr+ki*I)y]Sin[kn*y]/y,{y,0,2}] written as
 Integrate[Exp[I(kr+ki*I)y]Sin[kn*y]/y,{y,0,2}] evaluates
to (after grouping (kr+I*ki)):

I/4(2ExpIntegralEi[2I((kr+I*ki)-kn)]-
    2ExpIntegralEi[2I((kr+I*ki)+kn)]+
     Log[1/(I((kr+I*ki)-kn))]-Log[I((kr+I*ki)-kn)]-
     Log[1/(I((kr+I*ki)+kn))]+Log[I((kr+I*ki)+kn)])

Substituting this result also makes the plot work:

With[{h=1},
 With[{a=0.0001,kn=Pi/h,kr=3.050},
  Plot[
   Abs[
    (kn^2-(kr+ki*I)^2)
      (4h(Log[4h/a]-NIntegrate[(1-Exp[I(kr+ki*I)y*Cos[kn*y]])/y,{y,0,2}])+
        I/((kr+ki*I)+kn)(Exp[I((kr+ki*I)+kn)h]-1)+
        I/((kr+ki*I)-kn)(Exp[2I((kr+ki*I)-kn)h]-1))-
      (kn^2+(kr+ki*I)^2)I/4
       (2ExpIntegralEi[2I((kr+I*ki)-kn)]-
        2ExpIntegralEi[2I((kr+I*ki)+kn)]+
        Log[1/(I((kr+I*ki)-kn))]-Log[I((kr+I*ki)-kn)]-
        Log[1/(I((kr+I*ki)+kn))]+Log[I((kr+I*ki)+kn)])],{ki,-0.23,-0.10}]]]

3) Combining both NIntegrate functions into one also works:

With[{h=1},
 With[{a=0.0001,kn=Pi/h,kr=3.050},
  Plot[Abs[(kn^2-(kr+ki*I)^2)(4h*Log[4h/a]+
        I/((kr+ki*I)+kn)(Exp[2I((kr+ki*I)+kn)h]-1)+
        I/((kr+ki*I)-kn)(Exp[2I((kr+ki*I)-kn)h]-1))-
     NIntegrate[(4h(kn^2-(kr+ki*I)^2)(1-Exp[I(kr+ki*I)y*Cos[kn*y]])+
        (kn^2+(kr+ki*I)^2)Exp[I(kr+ki*I)y]Sin[kn*y])/y,
       {y,0,2}]],{ki,-0.23,-0.10}]]]

4) Without any implied criticism, I would like to point out that the form
Exp[I(kr+ki*I)y*Cos[kn*y]] is unusual. Is it actually supposed to be
Exp[I(kr+ki*I)y]*Cos[kn*y]? If so,

NIntegrate[(1-Exp[I(kr+ki*I)y*Cos[kn*y]])/y,{y,0,2}] written as
 Integrate[(1-Exp[I(kr+ki*I)y]*Cos[kn*y])/y,{y,0,2}] evaluates
to (after grouping (kr+I*ki)):

1/4(4EulerGamma-2ExpIntegralEi[2I((kr+I*ki)-kn)]-
     2ExpIntegralEi[2I((kr+I*ki)+kn)]+Log[16]-
     Log[1/(I((kr+I*ki)-kn))]+Log[I((kr+I*ki)-kn)]-
     Log[1/(I((kr+I*ki)+kn))]+Log[I((kr+I*ki)+kn)])

Substituting this result also makes a (different) plot that works:

With[{h=1},
 With[{a=0.0001,kn=Pi/h,kr=3.050},
  Plot[
   Abs[
    (kn^2-(kr+ki*I)^2)
      (4h(Log[4h/a]-1/4(4EulerGamma-2ExpIntegralEi[2I((kr+I*ki)-kn)]-
        2ExpIntegralEi[2I((kr+I*ki)+kn)]+Log[16]-
        Log[1/(I((kr+I*ki)-kn))]+Log[I((kr+I*ki)-kn)]-
        Log[1/(I((kr+I*ki)+kn))]+Log[I((kr+I*ki)+kn)]))+
        I/((kr+ki*I)+kn)(Exp[I((kr+ki*I)+kn)h]-1)+
        I/((kr+ki*I)-kn)(Exp[2I((kr+ki*I)-kn)h]-1))-
      (kn^2+(kr+ki*I)^2)I/4
       (2ExpIntegralEi[2I((kr+I*ki)-kn)]-
        2ExpIntegralEi[2I((kr+I*ki)+kn)]+
        Log[1/(I((kr+I*ki)-kn))]-Log[I((kr+I*ki)-kn)]-
        Log[1/(I((kr+I*ki)+kn))]+Log[I((kr+I*ki)+kn)])],{ki,-0.23,-0.10}]]]

Hope this helps...





  • Prev by Date: Time series minima and maxima
  • Next by Date: Re: Mathematica 20x slower than Java at arithmetic/special functions, is
  • Previous by thread: Re: Plot works in Mathematca 7 but not in Mathematica 8
  • Next by thread: Converting XML DATEEVENT to Mathematica AbsoluteTime