Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8158

Re: compile a numerical integral

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: compile a numerical integral
Date 2012-01-25 12:11 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jfori9$68e$1@smc.vnet.net> (permalink)

Show all headers | View raw


On 1/24/12 at 5:07 AM, ruth.lazkoz@ehu.es (Ruth Lazkoz S=C3=A1ez) wrote:

>I am working to make a code faster using compile and failed at the
>very beginning. Is there a way to make a version that works?

>f=Compile[{u},NIntegrate[x*u,{x,0.,#}]&/@{1,2,3}]

Try,

f = Compile[{{u, _Real}, {a, _Real}}, NIntegrate[u x, {x, 0, a}]]

But, while this compiles, it would be very surprising if there
were any measurable improvement in execution speed. Compile
cannot optimize built-in functions. Calls to built-in functions
already call compiled code. What Compile can do is Compile an
Mathematica expression. That is:

u*x

could be compiled by Compile. But, it is very unlikely you will
see any significant improvement for such a simple expression.
You would almost certainly get better performance by doing

In[2]:= int = Integrate[u x, {x, 0, a}]

Out[2]= (a^2*u)/2

and then supplying numeric values for u,a.

or by doing:

g = Compile[{{u, _Real}, {a, _Real}},
   Evaluate[Integrate[u x, {x, 0, a}]]]

That is telling Mathematica to evaluate the integral
symbolically then compile the result.

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: compile a numerical integral Bill Rowe <readnews@sbcglobal.net> - 2012-01-25 12:11 +0000

csiph-web