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


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

Re: compile a numerical integral

Started byBill Rowe <readnews@sbcglobal.net>
First post2012-01-25 12:11 +0000
Last post2012-01-25 12:11 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

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

#8158 — Re: compile a numerical integral

FromBill Rowe <readnews@sbcglobal.net>
Date2012-01-25 12:11 +0000
SubjectRe: compile a numerical integral
Message-ID<jfori9$68e$1@smc.vnet.net>
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.

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web