Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3596266
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:57:57+00:00 2026-05-18T19:57:57+00:00

I want to modify Mathematica’s Interpolation[] function (in 1 dimension) by replacing extrapolation with

  • 0

I want to “modify” Mathematica’s Interpolation[] function (in 1
dimension) by replacing extrapolation with constant values when the
input is out of range.

In other words, if the interpolation domain is [1,20] and f[1]==7 and
f[20]==12, I want:

f[x] = 7 for x<=1 
f[x] = 12 for x>=20 
f[x] = Interpolation[...] 

However, this fails:

(* interpolation w cutoff *) 
interpcut[r_] := Module[{s, minpair, maxpair}, 

(* sort array by x coord *) 
s = Sort[r, #1[[1]] < #2[[1]] &]; 

(* find min x value and corresponding y value *) 
minpair = s[[1]]; 

(* ditto for max x value *) 
maxpair = s[[-1]]; 

(* return the pure function representing cutoff interpolation *) 
Piecewise[{ 
{minpair[[2]] &, #1 < minpair[[1]] &}, 
{maxpair[[2]] &, #1 > maxpair[[1]] &}, 
{Interpolation[r], True} 
}]] 

test = Table[{x,Prime[x]},{x,1,10}] 

InputForm[interpcut[test]] 

Piecewise[{{minpair$59[[2]] & , #1 < minpair$59[[1]] & },  
  {maxpair$59[[2]] & , #1 > maxpair$59[[1]] & }},  
 InterpolatingFunction[{{1, 10}}, {3, 1, 0, {10}, {4}, 0, 0, 0, 0},  
  {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, {{2}, {3}, {5}, {7}, {11}, {13}, {17},  
   {19}, {23}, {29}}, {Automatic}]] 

I’m sure I’m missing something basic. What?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:57:57+00:00Added an answer on May 18, 2026 at 7:57 pm

    Function definition

    interpcut[r_, x_] := 
       Module[{s},(*sort array by x coord*)
           s = SortBy[r, First];
           Piecewise[
            {{First[s][[2]], x < First[s][[1]]},
             {Last [s][[2]], x > Last [s][[1]]},
             {Interpolation[r][x], True}}]]; 
    

    Test

    test = Table[{x, Prime[x]}, {x, 1, 10}];
    f[x_] := interpcut[test, x]
    Plot[f[x], {x, -10, 30}]  
    

    alt text

    Edit

    Answering your comment about pure functions.

    I did it that way just for clarity, not for cheating. For using pure functions just “follow the recipe”:

    interpcut[r_] := Module[{s},
      s = SortBy[r, First];
      Function[Piecewise[
        {{First[s][[2]], # < First[s][[1]]},
         {Last [s][[2]], # > Last [s][[1]]},
         {Interpolation[r][#], True}}]]
      ] 
    
    test = Table[{x, Prime[x]}, {x, 1, 10}];
    f = interpcut[test] // InputForm
    Plot[interpcut[test][x], {x, -10, 30}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to modify Mathematica's Interpolation[] function (in 1 dimension) by replacing extrapolation with
I want to modify a local variable in a function of extension method. See
I want to modify the following extract numbers function below to check if the
below is the code which i want to modify $input = fopen(php://input, r); $temp
I have a function and I want to modify cardString[] that is passed to
I want to modify the glBindTexture() function to keep track of the previously binded
I want to modify the solution for highlighting trailing whitespace described here by NOT
I want to modify some code in the Eclipse JDT itself (In the Debug
I want to modify a connection string that's hard-coded in a Java application (jar
I want to modify a view from Action Helper in Zend Framework in preDispatch()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.