Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: How to enter an integral in a formula and have

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108984] Re: How to enter an integral in a formula and have
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Fri, 9 Apr 2010 03:31:59 -0400 (EDT)

Hi Jim,

If you are only interested in numerical values, then the best probably is to

explicitly specify that your function <f> expects a numerical input:

Clear[f];
f[x_?NumericQ] := NIntegrate[g[y, x], {y, 0, 1}]

If you simply want to delay evaluation until the function <f> is called,
this is achieved
simply by using delayed assignment (SetDelayed):

Clear[ff];
ff[x_] := Integrate[g[y, x], {y, 0, 1}]

In this case however, every call to <f> will result in re-evaluation of the
integral, which may
be not what you want (and will be also much slower).

Computing your function on a list of values amounts to Map-ping it on this
list:


In[5]:= Map[f, Range[10]]

Out[5]= {1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5}

In[6]:= Map[ff,Range[10]]
Out[6]= {3/2,5/2,7/2,9/2,11/2,13/2,15/2,17/2,19/2,21/2}


Finally, if you want for some reason to work with larger expression where
Integrate will be present but will
not evaluate, you can enclose the code that produces that expression and
works on it, in Block[{Integrate},...].
For example

In[7]:= Block[{Integrate},Hold[Evaluate[ff[x]]]]

Out[7]= Hold[\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(1\)]\(\((x + y)\)
\[DifferentialD]y\)\)]

Once you leave the scope of Block however, all such integrals will evaluate
symbolically (that's why
I used Hold here to prevent this), so it's up to you then do decide what to
do with such an expression.
You could, for example, transform it with some set of transformation rules
inside Block, according
to your needs.

Hope this helps.

Regards,
Leonid


On Thu, Apr 8, 2010 at 7:02 AM, Jim Rockford <jim.rockford1 at gmail.com>wrote:

> I have a certain integral, part of a larger expression, that can be
> expressed in terms of incomplete gamma functions by Mathematica.  But
> in carrying out the definite integral and forcing it to be written in
> terms of gamma functions, this introduces branch points and other
> unnecessary complications.  I want the integral left alone and
> evaluated numerically, but I still want to express the general formula
> for this large expression with the unevaluated integral in place.
>
> For example, I'd like
>
> f[x_] = (stuff) + int_{0}^{1} (g[s,x]) ds
>
> where the definite integral is expressed in the usual Mathematica
> notation.
>
> What I do *not* want Mathematica to do at this stage is to do the
> integral analytically and write it in terms of special functions.
> Instead, I just want to later make a list of values for  f[x]  and
> have the integral done numerically.
>
> How can I program this?
>
> Thanks,
> Jim
>
>


  • Prev by Date: Re: Automatic method in Eigenvalues
  • Next by Date: Surprising behaviour with nested pure functions and local parameter
  • Previous by thread: Mathematica's beauty
  • Next by thread: Surprising behaviour with nested pure functions and local parameter