8

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?

Quark Soup
  • 1,610
  • 9
  • 14

1 Answers1

12

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}]

Mathematica graphics

C. E.
  • 70,533
  • 6
  • 140
  • 264