# How do you interpolate outside the range of data?

I've got a simple interpolation function using data from an external program. For values above 3,000, the function reaches a limit.

FreeElectronFractionData = {{3000.000, 1.0829044}, {2999.700, 1.0828636}, {2999.400, 1.0828634}, {2999.100, 1.0828633}, ... {2.701, 0.0000003}, {2.401, 0.0000003}, {2.101, 0.0000003}, {1.801, 0.0000003}, {1.501, 0.0000003}, {1.201, 0.0000003}, {0.901, 0.0000003}, {0.601, 0.0000003}, {0.301, 0.0000003}, {0.000, 0.0000003}};

FreeElectronFraction := Interpolation[FreeElectronFractionData];


When I give the FreeElectronFraction function a value greater than 3,000, I get the message:

FreeElectronFraction[4000]
Input value {4000} lies outside the range of data in the interpolating function. Extrapolation will be used.


I don't want this. I know that anything over 3,000 has a value of 1.0829. What I want is something like:

FreeElectronFractionData = {{∞, 1.0829044}, {3000.000, 1.0829044}, {2999.700, 1.0828636}, ...


But $$\infty$$ doesn't appear to be a real number, so Mathematica rejects it. How do you handle the case of a simple interpolation of a data set with a limit?

You can use the undocumented argument "ExtrapolationHandler", which I learned about here, together with ConditionalExpression as recommended by @CarlWoll in the comments:

freeElectronFractionData = {{3000.000, 1.0829044}, {2999.700,
1.0828636}, {2999.400, 1.0828634}, {2999.100, 1.0828633}, {2.701,
0.0000003}, {2.401, 0.0000003}, {2.101, 0.0000003}, {1.801,
0.0000003}, {1.501, 0.0000003}, {1.201, 0.0000003}, {0.901,
0.0000003}, {0.601, 0.0000003}, {0.301, 0.0000003}, {0.000,
0.0000003}};

freeElectronFraction = Interpolation[
freeElectronFractionData,
"ExtrapolationHandler" -> {
ConditionalExpression[1.0829044, # > 3000] &,
"WarningMessage" -> False
}
];

Plot[freeElectronFraction[x], {x, 0, 5000}]


• @DonaldAirey Posted something better now. Commented Aug 24, 2019 at 15:20
• Yeah, that looks more like it. I saw the "ExtrapolationHandler", but like you said, there wasn't enough documentation behind it that I could use it. Good work. Commented Aug 24, 2019 at 15:27
• I would use ConditionalExpression[1.0829044, #>3000]& instead, so that you don't return 1.0829044 for numbers below 0. Commented Aug 24, 2019 at 15:29
• @CarlWoll Good idea, I updated to add that. Commented Aug 24, 2019 at 15:32
• This solution still returns an error when you give it $\infty$ as an argument. Commented Aug 24, 2019 at 18:44