Message Boards Message Boards

Plotting functions defined by Integrate

Posted 2 years ago

Got a new version of Mathematica 12.3 and tried to run some old notebooks that ran graciously in 2005... The Plot stalls. All other old notebooks that use Integrate in functions to be plotted freeze as well. Many thanks for any hint.

Attachments:
POSTED BY: Brani Vidakovic
2 Replies

Dear Gianluca -- thanks for the suggestions, the Chop and = instead of := work like a champ!

POSTED BY: Brani Vidakovic

I would use = instead of :=, so that the integrals are evaluated symbolically once and for all, and a Chop to get rid of small imaginary numerical noise:

Clear[m, ep, x];
ma[x_, m_, ep_] = 
  ep * 1/( Sqrt[2 Pi] )*Exp[-1/2  x^2] + (1 - ep)*
    Integrate[ 
     1/(m Sqrt[2 Pi] )* Cos[Pi th/(2 m)]^2 * 
      Exp[-1/2 (x - th)^2], {th, -m, m}];
mader[x_, m_, ep_] = (ma[x + 0.001, m, ep] - ma[x - 0.001, m, ep])/
   0.002;
mao[x_, m_, ep_] = 
  ep*1/(Sqrt[2 Pi])*Exp[-1/2 x^2] + (1 - ep)*
    Integrate[1/(2 m Sqrt[2 Pi])*Exp[-1/2 (x - th)^2], {th, -m, m}];
madero[x_, m_, ep_] = (mao[x + 0.001, m, ep] - mao[x - 0.001, m, ep])/
   0.002;
With[{m = 20, ep = 0.8},
 Plot[{x, Chop[x + madero[x, m, ep]/mao[x, m, ep]], 
   Chop[x + mader[x, m, ep]/ma[x, m, ep]]}, {x, -m - 5, m + 5}, 
  PlotStyle -> {{GrayLevel[0]}, {Hue[5/8]}, {Hue[0]}}, 
  AspectRatio -> Automatic]]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract