# InterpolatingFunction::dmval error in the Piecewise function with an interpolation funcion included

I have a set of data, first I deal the data with an Interpolation function.

excitef1 = Interpolation[ps1]


Then I use a Piecewise function to expand the range of the function

excite1 = Piecewise[{{excitef1[r], 4.97 <= r <= 22}, {0, r > 22}}]


The Piecewise function is then used to solve a differential equation

    exciteshiftfunction =
ParallelTable[NDSolveValue[{w1'[r] + (20/10*mass*excite1 + i*(i + 1)/r^2)/wave
*(Sin[wave*r + w1[r]])^2 == 0, w1[auo] == -wave*auo},
w1, {r, 5, 10000000}, MaxSteps -> Infinity], {i, 0, 120}];


where mass, wave, auo are constants.

but the reslut returns an error warning:

InterpolatingFunction::dmval: Input value {1035.17} lies outside the range of data in the interpolating function. Extrapolation will be used.


I tried many methods to solve this error, but only get similar error warnings or software crashs due to insufficient system memory.

I appreciate any help, best regards sincerely.

Ps: the data interpolated and the constants used are attached below.

ps1 = {{4.96735, 0.00729014}, {5.02197, 0.00714075}, {5.09024,
0.00701852}, {5.19949, 0.00686913}, {5.32236, 0.00673333}, {5.47255,
0.0066111}, {5.62275, 0.00650245}, {5.77295, 0.00639381}, {5.9095,
0.00627158}, {6.05969, 0.00614936}, {6.18258, 0.00601355}, {6.33278,
0.00586416}, {6.51028, 0.00566045}, {6.63317, 0.00547032}, {6.7697,
0.00528019}, {6.87893, 0.00511722}, {7.01548,
0.00489993}, {7.15201, 0.0047098}, {7.26126, 0.00453325}, {7.35682,
0.0043567}, {7.46607, 0.00418015}, {7.54798, 0.00404434}, {7.67087,
0.00386779}, {7.79376, 0.00367766}, {7.90299, 0.00347395}, {8.01222,
0.00331098}, {8.1078, 0.00316159}, {8.24435, 0.0029443}, {8.39454,
0.00275417}, {8.50377, 0.0025912}, {8.59935, 0.00246898}, {8.70858,
0.00230601}, {8.7905, 0.00221094}, {8.89974, 0.00208872}, {9.02263,
0.00193933}, {9.17283, 0.00178994}, {9.30936, 0.00164055}, {9.44589,
0.00150474}, {9.62342, 0.00135536}, {9.77361,
0.00126029}, {9.93745, 0.0011109}, {10.1286, 0.00100226}, {10.2788,
0.000880031}, {10.4836, 0.000771386}, {10.6475,
0.000703482}, {10.8386, 0.000621997}, {10.9888,
0.000554094}, {11.1663, 0.00048619}, {11.3575,
0.000431867}, {11.5486, 0.000363964}, {11.7398,
0.000336802}, {11.9446, 0.00029606}, {12.1221,
0.000255318}, {12.286, 0.000214576}, {12.4498, 0.000200995}, {12.6,
0.000160253}, {12.7639, 0.000146672}, {12.955,
0.000133091}, {13.0506, 0.000133091}, {13.2281,
0.00010593}, {13.3919, 0.00010593}, {13.5694,
0.000092349}, {13.7879, 0.0000651875}, {13.9791,
0.0000651875}, {14.1975, 0.000038026}, {14.4297,
0.000038026}, {14.7027, 0.000038026}, {15.0304,
0.0000244453}, {15.2625, 0.0000244453}, {15.5356,
0.0000244453}, {15.8224, 0.0000108646}, {15.9726,
0.0000108646}, {16.2047, 0.0000108646}, {16.4505,
0.0000244453}, {16.6689, 0.0000108646}, {16.8191, 0.}, {17.2424,
0.}, {17.5428, 0.}, {17.9661, 0.}, {18.3484, 0.}, {18.8809,
0.}, {19.2905, 0.}, {19.6728, 0.}, {20.0415, 0.}, {20.4375,
0.}, {20.8061, 0.}, {21.1748, 0.}, {21.3659, 0.}, {21.7619,
0.}, {22.1306, 0.}, {22.3217, 0.}};

mass=6969.88576565879970171872799434;
energy= 0.00142333647775022850583870534382;
wave=4.45432209343110941926594969308;

• I completed the definition of ps1 as thought you meant. There are other undefined terms, though, so no one can test & analyze your code. Commented Jan 22, 2018 at 13:15
• Thanks for your comments, I have added the constants so that the code can be tested. Commented Jan 22, 2018 at 13:29

NDSolve rewrites the Piecewise function in setting up the event handling (the change of formula in a Piecewise function is treated as a discontinuity in the function and/or its derivative whether or not it actually is, and that is handled as an event). One way is to protect the InterpolatingFunction thus:

ClearAll[ef1];
ef1[r_?NumericQ /; 4.97 <= r <= 22] := excitef1[r];
ef1[_?NumericQ] = 0;
excite1 = Piecewise[{{ef1[r], 4.97 <= r <= 22}, {0, r > 22}}];


This is basically what is going on, where s is the event variable created by NDSolve:

excite1 = Piecewise[{{excitef1[r], 4.97 <= r <= 22}, {0, r > 22}}];
Block[{r = 1000}, excite1]
(*  0  *)

excite1 = Piecewise[{{excitef1[r], s < 0}, {0, r > 22}}];
Block[{r = 1000}, excite1]


InterpolatingFunction::dmval: Input value {1000} lies outside the range of data in the interpolating function. Extrapolation will be used.

(*  Piecewise[{{0., s < 0}}, 0]  *)