Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm looking at a piecewise function of two lines, which has a kink, such as:

f1[p_] := 1.41 * p + 2*^8;
f2[p_] := 1.45 * p + 1.9584*^8;
f3[p_] := Piecewise[{{f1[p], p <= 1.04*^8}, {f2[p], p > 1.04*^8}}];

I want to work with a function which is linear on both sides of the kink like above, but is smooth in a small region around the kink as an approximation to the above function.

I'd like to use Interpolation[] to find a smooth function to approximate a region of width delta p around the kink, p = 1.04 * 10^8.

However Interpolation can give me a function which will just introduce more kinks out the boundaries with f1 and f2. Is there a way I can enforce boundary conditions on Interpolation[] so that it can give me a smooth function in this region?

Edit to clarify: The boundary I'm considering is arbitrary; it is just centered around 1.04*10^8. For example, I tried using a region of width .01*10^8 centered around this value, so my code was:

region = Interpolation[{{1.03*^8, f1[1.03*^8]}, {1.035*^8, f1[1.035*^8]}, {1.045*^8, f2[1.045*^8]}, {1.05*^8, f2[1.05*^8]}}];

But if you plot this, it will not be smooth with the rest of the function (i.e., it doesn't have a slope of 1.41 at p=1.03*^8, and 1.45 at p=1.05*^8. I want to enforce those slopes at those values, or any other arbitrary value).

share|improve this question
    
Could you add the code for Interpolation that you have tried? What are the boundaries of p? –  Jens Aug 2 '13 at 19:10
    
Edited my question above to address this –  psachdeva Aug 2 '13 at 19:17

1 Answer 1

Since your goal is to enforce the derivatives, a better way to use Interpolation here is to apply it to the derivative of your data, as follows:

points = {1.03, 1.035, 1.045, 1.05} 10^8;

derivs = Map[f3', points]

(* ==> {1.41, 1.41, 1.45, 1.45} *)

regionSlope = Interpolation[Transpose[{points, derivs}]];

Plot[
 Evaluate[{D[f3[p], p], regionSlope[p]} /. p -> p1], {p1, 1.03 10^8, 
  1.05 10^8}]

derivs

The slopes are now matched at the boundaries. The original function can be interpolated by the integral of the InterpolatingFunction obtained above:

Clear[region]

region[t_?NumericQ] := 
 f3[points[[1]]] + NIntegrate[regionSlope[p], {p, points[[1]], t}]

Plot[Evaluate[{f3[p], region[p]}], {p, 1.03 10^8, 1.05 10^8}]

integral

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.