Message Boards Message Boards

0
|
5458 Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Integrate product of linear interpolation functions?

Posted 10 years ago

I have made some simple linear interpolation functions:

nM = 7;
xi = Table[2 (j - 1)/(nM - 1), {j, nM}];\[CurlyPhi][1] = 
 Interpolation[{{xi[[1]], 1}, {xi[[2]], 0}, {xi[[nM]], 0}}, 
  InterpolationOrder -> 1]; \[CurlyPhi][2] = 
 Interpolation[{{xi[[1]], 0}, {xi[[2]], 1}, {xi[[3]], 0}, {xi[[nM]], 
    0}}, InterpolationOrder -> 1];
\[CurlyPhi][nM - 1] = 
  Interpolation[{{xi[[1]], 0}, {xi[[nM - 2]], 0}, {xi[[nM - 1]], 
     1}, {xi[[nM]], 0}}, InterpolationOrder -> 1];
\[CurlyPhi][nM] = 
  Interpolation[{{xi[[1]], 0}, {xi[[nM - 1]], 0}, {xi[[nM]], 1}}, 
   InterpolationOrder -> 1];
Do[\[CurlyPhi][j] = 
   Interpolation[{{xi[[1]], 0}, {xi[[j - 1]], 0}, {xi[[j]], 
      1}, {xi[[j + 1]], 0}, {xi[[nM]], 0}}, 
    InterpolationOrder -> 1], {j, 3, nM - 2}];

The Integrate[ ] function can do a definite integral without a problem. For example

\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(2\)]\(\(\[CurlyPhi][
     1]'\)[x] \[DifferentialD]x\)\)

gives the exact answer -1. However the definite integral of the product of two such functions returns unevaluated, even though the piecewise polynomial ought to be integrable. For example

\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(2\)]\(\(\[CurlyPhi][
     1]'\)[x] \(\[CurlyPhi][4]'\)[x] \[DifferentialD]x\)\)

returns

\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(2\)]\(\(\*
TagBox[
RowBox[{"InterpolatingFunction", "[", 
RowBox[{
RowBox[{"{", 
RowBox[{"{", 
RowBox[{"0", ",", "2"}], "}"}], "}"}], ",", "\<\"<>\"\>"}], "]"}],
False,
Editable->False][x]\ \*
TagBox[
RowBox[{"InterpolatingFunction", "[", 
RowBox[{
RowBox[{"{", 
RowBox[{"{", 
RowBox[{"0", ",", "2"}], "}"}], "}"}], ",", "\<\"<>\"\>"}], "]"}],
False,
Editable->False][x]\) \[DifferentialD]x\)\)

What went wrong here?

Thanks in advance for helping!

POSTED BY: C L
5 Replies
Posted 10 years ago

Piecewise[ ] works great! Thank you!

POSTED BY: C L

Rather than nested is statements, the better approach would be to use the function Piecewise:

http://reference.wolfram.com/language/ref/Piecewise.html

POSTED BY: David Reiss
Posted 10 years ago

OK just did a quick experiment. The bottom line:

The Interpolation function is really easy to set up with nice clean code. But afterwards it's nearly useless when there are unknown coefficients.

The nested If[ ] statements is harder to set up and uglier to look at. But the integration with unknown coefficients works like a charm. :)

Hope this helps someone that's doing similar kind of computation.

POSTED BY: C L
Posted 10 years ago

Thanks! The problem with NIntegrate is that it does not work when there are unknown coefficient of the integrand. In other words it can't do

NIntegrate[ A[1] fn[x] + ... ] = A[1] NIntegrate[ fn[x] ] + ...

where fn[x] can be evaluate to numerical values but A[1] is an unknown coefficient.

The actual integrand have many terms and it will be tedious to rewrite the whole thing by hand. Is there a way to instruct NIntegrate[ ] to integrate just the numerical part and leave the unknown coefficient alone?

Another approach I thought of is to rewrite the interpolation function as a bunch of nested If[ ] statements. Would that be more integrable?

POSTED BY: C L
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract