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.

For an InterpolatingFunction $y:\ \mathbb{R}\to\mathbb{R}^2$, Plus is unaware of this, so when I do any modifications to it in an unevaluated form, it breaks the result

y = Interpolation[Table[{i, RandomReal[{0, 1}, 2]}, {i, 1, 10}]];
y[t]
y[t] + {1, 2}

(* InterpolatingFunction[{{1.,10.}},<>][t]`
{1+InterpolatingFunction[{{1.,10.}},<>][t],2+InterpolatingFunction[{{1.,10.}},<>][t]} *)

I ran into it doing things like:

y = Interpolation[Table[{i, RandomReal[{0, 1}, 2]}, {i, 1, 10}]];
f[t_] := Piecewise[{{ {1, 2} + y[t], t < 5}}];
df[t_] := Evaluate[D[f[t], t]]
df[t]
df[3]

And I can't figure out how to prevent expressions like {1,2} + y[t] from being evaluated while still being able to differentiate them. If Plus just realized that y[t] is $\mathbb{R}^2$ valued, I think that would simplify everything for me. Is there some way to set this property?

share|improve this question
    
I suppose y[t_] = {Interpolation[Table[{i, RandomReal[{0, 1}]}, {i, 1, 10}]][t], Interpolation[Table[{i, RandomReal[{0, 1}]}, {i, 1, 10}]][t]} is not what you're looking for? –  Sjoerd C. de Vries Nov 12 '12 at 21:13
    
Started rewriting my code to split everything up like that, but was hoping for some Hold magic :) –  ssch Nov 12 '12 at 21:23
add comment

1 Answer 1

up vote 5 down vote accepted

Using the InterpolatingFunctionAnatomy package one can implement the threading explicitly.

y = Interpolation[Table[{i, RandomReal[{0, 1}, 2]}, {i, 1, 10}]];

<< DifferentialEquations`InterpolatingFunctionAnatomy`

yy = Interpolation[
  MapThread[
   List, {InterpolatingFunctionGrid[y], {1, 2} + # & /@ 
     InterpolatingFunctionValuesOnGrid[y]}], 
  InterpolationOrder -> 
   First[InterpolatingFunctionInterpolationOrder[y]]]

enter image description here

share|improve this answer
    
Nice! Trying to override Plus Unprotect[Plus]; Plus[c_List, f_InterpolatingFunction] := Interpolation[ MapThread[ List, {InterpolatingFunctionGrid[f], c + # & /@ InterpolatingFunctionValuesOnGrid[f]}], InterpolationOrder -> First[InterpolatingFunctionInterpolationOrder[f]]]; But I think I have to hunt the documentation a bit to see how to do it properly –  ssch Nov 12 '12 at 21:31
2  
(Of course, if you're aware of the direct way to access those properties (e.g. y["Grid"] and y["ValuesOnGrid"]), you don't need to load the package...) –  J. M. Nov 12 '12 at 22:02
    
@J.M. ...and there's one of those features I didn't know about. What other "properties" of InterpolatingFunction are there? –  Mr.Wizard Nov 12 '12 at 22:04
3  
It seems the answer to my question is: "Coordinates", "DerivativeOrder", "Domain", "Evaluate", "Grid", "InterpolationOrder", "MethodInformation", "Methods", "Properties", "ValuesOnGrid" –  Mr.Wizard Nov 12 '12 at 22:11
1  
@Mr.Wizard, for reference, y["Methods"] will return that list of properties supported by an InterpolatingFunction[]. –  J. M. Nov 13 '12 at 16:16
add comment

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.