# Extracting an equation from an interpolated function

Im trying to use LibraryLink to do some calculations in C but part of the expression i want to calculate is an Interpolating Function. C cant use that obviously so I'm trying to shift it to a data type that i can use.

So first question, does an interpolated function exist as an equation as in y = ax^2 + bx + c, if yes, can that be extracted, if not, can it be used with something like InterpolatingPolynomial to create an equation.

The most obvious solution is to create an interpolating polynomial to begin with but the existing code is quite extensive so it would involve a lot of modifications, which is fine i guess but i thought i would check if anyone had any ideas first.

Thanks in advance =)

• One of the problem with this approach is that the best way for evaluating the interpolating polynomial is usually not explicitly writing out the formula in C. Question: Were you planning to simply paste that equation into C code or were you looking to pass an interpolating function to some LibraryLink code dynamically? If the latter: You can call back to Mathematica from LibraryLink and ask it to evaluate the interpolating function, but it's not going to be very fast. – Szabolcs Jan 12 '15 at 23:25
• You can also extract the underlying data from an InterpolatingFunction and re-implement the interpolation method in C. Try ifun["Methods"] or google for "InterpolatingFunctionAnatomy". – Szabolcs Jan 12 '15 at 23:27
• The function in C (actually C++ now that i think about it) is a numerical differential equation solver so it is only passed the equation once and it computes multiple times (probably thousands) so i think you're right, the best approach is to interpolate the base data in the C++ code. And yeah the end goal is optimisation so calling back to mathematica isn't so desirable. – Nicholas Gaffney-Henderson Jan 12 '15 at 23:37
• Is it a variable time step solver? If it' a fixed time step solver, you could pre-generate all the data you need in Mathematica, in a single step, and pass them to the C side. – Szabolcs Jan 12 '15 at 23:50
• I haven't decided yet but most likely ill be using adaptive step size. I need to work with stiff systems occasionally so restraining myself to static step sizes now would make that excruciating at a later point. – Nicholas Gaffney-Henderson Jan 12 '15 at 23:55