Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.9K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Evaluating definite integral of expression containing InterpolationFunction

Posted 9 years ago

This problem appears in Mathematica 10.0.2, on OS X 10.7.

An InterpolatingFunction F[z] born by the successful solution "soln" of a set of algebraic differential equations can be used alone as the integrand of a definite integral with no problem, provided that the integrand appears as Evaluate[Fn[z]] /. soln]. But if one includes this in an expression as the integrand, however trivial, such as 2.0 Evaluate[Fn[z]] /. soln] , one gets only a symbolic result for the integral with no evaluation. Part of the notebook is attached. Suggestions?

thanks

Attachments:
POSTED BY: Andy Miller
4 Replies
Posted 9 years ago

Gianluca, which version of Mathematica did you use? thanks - I am still using 10.0 because my OS X is old.

I have plotted all of the results from my solution, including the one that can be integrated only alone, and they seem reasonable.

Yes, my notebook is only partial — as noted in a comment at the top, some functions appearing in the equations are themselves InterpolatingFunctions of data tables. And this equation set is an algebraic-differential initial-value problem. So it's more complicated.

POSTED BY: Andy Miller

This works fine:

soln = NDSolve[{q'[x] == q[x], q[0] == 1}, q, {x, 0, 1}];
NIntegrate[2 Evaluate[q[z] /. soln[[1]]], {z, 0., 1}]

Your soln may have some problems. From the file you provided I can't reproduce your values.

POSTED BY: Gianluca Gorni
Posted 9 years ago

Thanks Gianluca, but that doesn't help in my situation; I was surprised to find that Nintegrate is even worse:

Nintegrate[Evaluate[q[z] /. soln], {z, 0., L}] (* Nintegrate can't do even this! *)

Nintegrate[2.0 Evaluate[q[z] /. soln], {z, 0., L}] (* Nor this *)

There must be a simple solution, but I couldn't find it in the documentsÂ…

POSTED BY: Andy Miller

It is the factor 2 inside the integral that causes trouble. It seems that the symbolic integration routines of Integrate don't know how to treat composite objects such as 2*InterpolatingFunction[]:

points = {{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}};
ifun = Interpolation[points];
Integrate[2 ifun[x], {x, 0, 5}]

Use NIntegrate in those cases:

points = {{0, 0}, {1, 1}, {2, 3}, {3, 4}, {4, 3}, {5, 0}};
ifun = Interpolation[points];
NIntegrate[2 ifun[x], {x, 0, 5}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard