I've read the answers of
How to make use of an interpolating function outside of Mathematica?,
Interpreting the interpolating function and saving data to plot with external program,
I have not managed to extrapolate them to my problem. The difference is that in my case, the interpolating function is of Output dimension
2: it's a parametric function (several values for one $x$).
This is an example code:
pts = {{0.504`, 2.79`}, {0.519`, 2.7773}, {0.5349`,
2.7642`}, {0.5504`, 2.7515`}, {0.5666`, 2.7398}, {0.5858`,
2.7341`}, {0.5914`, 2.8566}, {0.5917`, 2.8364}, {0.5918`,
2.8766}, {0.5924`, 2.8164}, {0.5933`, 2.7963`}, {0.5935`,
2.7525`}, {0.5935`, 2.8966`}, {0.5940, 2.7763`}, {0.5974`, 2.9163`}}
path = First@FindCurvePath@Standardize@pts;
curve = Interpolation[#] &@MapIndexed[{#2[[1]], #1} &, pts[[path]]];
Show[ParametricPlot[curve[t], {t, 1, Length[path]},
AspectRatio -> 3/4, PlotStyle -> Red], ListPlot[pts]]
In the end, I want to export the function curve
in Asymptote, which uses a syntax similar to C. For this, I plan to manipulate strings to replace the Piecewise
syntax into if(x<3) {return x*.... ;}
. Although it is a bit tedious, it should work. My problem is accessing the Interpolatingfunction curve
, as explained above.
Concretely, I would like to have the piecewise polynomials expressions and their boundaries. Typically:
pos={{0.5,0.52},{0.52,0.54}...}
and expr={2.3+0.1*x-2.6*x^2, ...}
. The reason why I can't use the answers of the questions above is that InterpolationPolynomial
does not apply to a list of points, but to a indexed list of points (MapIndexed[{#2[[1]], #1} &, pts[[path]]]
).