Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

NIntegrate - bug??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85361] NIntegrate - bug??
  • From: Costa Bravo <laguna at aol.com>
  • Date: Thu, 7 Feb 2008 04:48:04 -0500 (EST)

I have defined the function of Exp with series

expN[x_, p1_] := Module[{min = 10^-20,s, u, j},
   s = 1; u = 1; j = 1;
   While[u *= N[p1*x/j, 20];
         s += u; j++;
         u > min*s];
     s]


The differences between Exp & expN

tp = 10; tk = 20;
Table[{x, Exp[x/5] - expN[x, 1/5]}, {x, tp, tk, 1}]

(* OK 0*10^-18 *)

(* I have integration Exp[x/5] with 'NIntegrate' *)

NIntegrate[Exp[x/5], {x, tp, tk}]

236.045   (* OK *)

(*  and  expN[x,1/5]  *)

NIntegrate[expN[x, 1/5], {x, tp, tk}]

40.    (* Bad !! *)

(* primitive integration expN   *)

t1 = Table[expN[x, 1/5], {x, tp, tk, 1/10}];
(Total[t1] - (t1[[1]] + t1[[-1]])/2)/10

236.0533...   (* ~OK *)

Why the integration of expN with NIntegrate is bad ?

Tested with Mathematica 5.0 ,5.2 and 6

PS
If defined function expN1 ( without While !!)

expN1[x_, p1_] := Module[{min = 10^-20, s, u, j},
   s = 1; u = 1;
   Do[u *= N[p1 x/j, 20]; s += u, {j, 30}];
   s]

NIntegrate[expN1[x, 1/5], {x, tp, tk}]

236.045 ( OK !!!! )


Thanks in advance.


Costa


  • Prev by Date: Re: Displaying Real Numbers
  • Next by Date: Re: Mathematica 6.0.0 no graphics output on Windows XP
  • Previous by thread: Mathematica, MacOS-X, Command-line
  • Next by thread: Memory and NDSolve