MathGroup Archive 2001

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

Search the Archive

Re: "Incremental Integration"?

  • To: mathgroup at
  • Subject: [mg31788] Re: [mg31774] "Incremental Integration"?
  • From: BobHanlon at
  • Date: Sun, 2 Dec 2001 04:25:04 -0500 (EST)
  • Sender: owner-wri-mathgroup at

In a message dated 2001/12/1 4:30:41 AM, siegman at writes:

>Given a rather messy function  f[x] , I want to make a Table of its integral
>from  x0 up to a set of equally spaced points xn = x0 + n*dx  with maximum
>xFinal -- in other words
>   g[x_] := NIntegrate[f[xi], {xi, x0, x}]
>   Table[ {x, g[x]}, {x, x0, xFinal, dx}]
>Is Mathematica smart enough to calculate each successive value using the
>previous value plus integration just over the increment in x to the next
>If not, what would be a clean and readable and also reasonably efficient
>way to 
>code this?
>[Note:  For me anyway, there's some emphasis on the "clean and readable"
>part -- 
>avoiding esoteric Mathematica syntax, not taking terseness as the ultimate

f[x_] := x^2;

x0=0; xFinal=10; dx=2;

rng = Range[x0, xFinal, dx];

      NIntegrate[f[x],{x,#[[1]],#[[2]]}]& /@ 

If readability is taken as the primary metric for code, then you will likely 
end up 
using predominantly procedural programming and not make effective use of 
functional programming.  If a complex expressions cannot be read easily, 
build the 
expression step-by-step and convert all of the steps (input and output) into 
a merged 
text cell to keep with the code.  This should be done in as general a form as 
practical.  For example, evaluate, merge, and convert to text the following

rng = {x0,x1,x2,x3};
Integrate[f[x], {x,#[[1]],#[[2]]}]& /@ %
(* NOTE: For NIntegrate the numbers are folded and each integral is evaluated 
once. *)

Bob Hanlon
Chantilly, VA  USA

  • Prev by Date: Re: Finding determinants of nxn matrices
  • Next by Date: Re: "Incremental Integration"?
  • Previous by thread: Re: "Incremental Integration"?
  • Next by thread: Re: "Incremental Integration"?