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.

This is a toy example of the question I have but I think it illustrates the point.

I have a function y[x] which is an interpolating function. Let's define it through:

y=y1 /. NDSolve[{y1''[x]+y1'[x]+y1[x]==0,y1[0]==1,y1'[0]==0},y1, {x, 0, 5}][[1, 1]]

I need to pass this function into another differential equation as the initial condition for the new system (it's time dependent). However, the new differential equation has to be in polar coordinates so I need the above function converted into polar coordinates.

Of course I could do this simply by writing:

Interpolation[{Sqrt[y[#]^2 + #^2], ArcTan[y[#]/#]} & /@ Range[0.001, 5, 0.1]]

Which will give me an interpolating function in the right coordinate system. However, with the above, I have had to chose the x values that I pass in by hand (ie. Range[0.001,10,0.1]). I would like to take as much data from the original InterpolatingFunction y[x] as I can. The grid within the interpolating function won't be even and there is, as far as I know, gradient data within the function as well.

I would like to be able to translate the original y[x] InterpolatingFunction into a θ[r] InterpolatingFunction with as much fidelity as I can.

I have seen that within Head[y[x]][[4]] there is data of the form {Developer`PackedArrayForm,List_,List_} but it's not clear what the syntax is.

If anybody knows how to pass my y[x] into a θ[r] as accurately as possible, I would be very grateful.

Edit

Thanks to mmal's comment I see a way forward. In the first link there is an answer to a similar question. If we load:

Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"]

Then we can define the following function:

Clear[reconstructInterpolatingFunction];
reconstructInterpolatingFunction[intf_InterpolatingFunction] := 
With[{data = intf[[4, 3]], 
step = Subtract @@ Reverse[Take[intf[[4, 2]], 2]], 
order = Developer`FromPackedArray@InterpolatingFunctionInterpolationOrder[intf], 
grid = InterpolatingFunctionGrid[intf]}, 
Interpolation[MapThread[Prepend, {Partition[data, step], grid}], 
InterpolationOrder -> order]];

Inspecting the term MapThread[Prepend, {Partition[data, step], grid}] for the InterpolatingFunction from NDSolve I find that the output is of the form:

{...,{{x},y[x],y'[x],y''[x]},...etc.}

Thus, this is what is needed to be transformed into polar coordinates and turned back into an InterpolatingFunction.

This is a much simpler task than I originally had so many thanks to mmal. I shan't be able to finish answering this question tonight so if anyone fancies playing with the derivative terms, please do so.

share|improve this question
    
Have you seen "DifferentialEquations`InterpolatingFunctionAnatomy`" package? Also look here –  mmal Jun 21 '13 at 21:25
    
In general, I'd use ArcTan[#, y[#]] instead of ArcTan[y[#]/#] for polar conversions. In any event, this seems to be a job for FunctionInterpolation[], which tries automatically picks abscissas to interpolate on. –  J. M. Jun 21 '13 at 21:45
    
@mmal, thank you that looks like it's going to answer the question though I see that the minimal example I have here isn't as complicated as the one that I will need to answer. I will add some comments to the question regarding your note. –  Jonathan Shock Jun 21 '13 at 21:45
    
You actually don't need to call the package, since the functionality is built-in, and that package is but a convenient inteface. Using your definition of y, try y["Properties"] to see a list of queries you can do. –  J. M. Jun 21 '13 at 22:07
1  
Hmm, odd; that used to work. Anyway, what I was getting at was that InterpolatingFunction[] objects support some properties. For instance, InterpolatingFunctionInterpolationOrder[y] is equivalent to y["InterpolationOrder"], while InterpolatingFunctionGrid[y] is internally done as y["Grid"]. All of the other functions in that utility package have property equivalents. –  J. M. Jun 21 '13 at 23:55

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.