你的一个公理是不正确的。Eigen (un) 支持样条插值,这与使用样条逼近函数不同。在前者中,样条必须通过数据点,而在近似中则不会,如spap2
. 使用以下示例,您可以检查输出以验证两者spline(times(i))
并sins(i)
给出相同的结果。
int main()
{
int size = 300;
Eigen::RowVectorXd times(size), sins(size);
times << 0, 0.0200668896321070, 0.0401337792642141, 0.0602006688963211, 0.0802675585284281, 0.100334448160535, 0.120401337792642, 0.140468227424749, 0.160535117056856, 0.180602006688963, 0.200668896321070, 0.220735785953177, 0.240802675585284, 0.260869565217391, 0.280936454849498, 0.301003344481605, 0.321070234113712, 0.341137123745819, 0.361204013377926, 0.381270903010033, 0.401337792642141, 0.421404682274248, 0.441471571906355, 0.461538461538462, 0.481605351170569, 0.501672240802676, 0.521739130434783, 0.541806020066890, 0.561872909698997, 0.581939799331104, 0.602006688963211, 0.622073578595318, 0.642140468227425, 0.662207357859532, 0.682274247491639, 0.702341137123746, 0.722408026755853, 0.742474916387960, 0.762541806020067, 0.782608695652174, 0.802675585284281, 0.822742474916388, 0.842809364548495, 0.862876254180602, 0.882943143812709, 0.903010033444816, 0.923076923076923, 0.943143812709030, 0.963210702341137, 0.983277591973244, 1.00334448160535, 1.02341137123746, 1.04347826086957, 1.06354515050167, 1.08361204013378, 1.10367892976589, 1.12374581939799, 1.14381270903010, 1.16387959866221, 1.18394648829431, 1.20401337792642, 1.22408026755853, 1.24414715719064, 1.26421404682274, 1.28428093645485, 1.30434782608696, 1.32441471571906, 1.34448160535117, 1.36454849498328, 1.38461538461538, 1.40468227424749, 1.42474916387960, 1.44481605351171, 1.46488294314381, 1.48494983277592, 1.50501672240803, 1.52508361204013, 1.54515050167224, 1.56521739130435, 1.58528428093646, 1.60535117056856, 1.62541806020067, 1.64548494983278, 1.66555183946488, 1.68561872909699, 1.70568561872910, 1.72575250836120, 1.74581939799331, 1.76588628762542, 1.78595317725753, 1.80602006688963, 1.82608695652174, 1.84615384615385, 1.86622073578595, 1.88628762541806, 1.90635451505017, 1.92642140468227, 1.94648829431438, 1.96655518394649, 1.98662207357860, 2.00668896321070, 2.02675585284281, 2.04682274247492, 2.06688963210702, 2.08695652173913, 2.10702341137124, 2.12709030100334, 2.14715719063545, 2.16722408026756, 2.18729096989967, 2.20735785953177, 2.22742474916388, 2.24749163879599, 2.26755852842809, 2.28762541806020, 2.30769230769231, 2.32775919732441, 2.34782608695652, 2.36789297658863, 2.38795986622074, 2.40802675585284, 2.42809364548495, 2.44816053511706, 2.46822742474916, 2.48829431438127, 2.50836120401338, 2.52842809364549, 2.54849498327759, 2.56856187290970, 2.58862876254181, 2.60869565217391, 2.62876254180602, 2.64882943143813, 2.66889632107023, 2.68896321070234, 2.70903010033445, 2.72909698996656, 2.74916387959866, 2.76923076923077, 2.78929765886288, 2.80936454849498, 2.82943143812709, 2.84949832775920, 2.86956521739130, 2.88963210702341, 2.90969899665552, 2.92976588628763, 2.94983277591973, 2.96989966555184, 2.98996655518395, 3.01003344481605, 3.03010033444816, 3.05016722408027, 3.07023411371237, 3.09030100334448, 3.11036789297659, 3.13043478260870, 3.15050167224080, 3.17056856187291, 3.19063545150502, 3.21070234113712, 3.23076923076923, 3.25083612040134, 3.27090301003345, 3.29096989966555, 3.31103678929766, 3.33110367892977, 3.35117056856187, 3.37123745819398, 3.39130434782609, 3.41137123745819, 3.43143812709030, 3.45150501672241, 3.47157190635452, 3.49163879598662, 3.51170568561873, 3.53177257525084, 3.55183946488294, 3.57190635451505, 3.59197324414716, 3.61204013377926, 3.63210702341137, 3.65217391304348, 3.67224080267559, 3.69230769230769, 3.71237458193980, 3.73244147157191, 3.75250836120401, 3.77257525083612, 3.79264214046823, 3.81270903010033, 3.83277591973244, 3.85284280936455, 3.87290969899666, 3.89297658862876, 3.91304347826087, 3.93311036789298, 3.95317725752508, 3.97324414715719, 3.99331103678930, 4.01337792642141, 4.03344481605351, 4.05351170568562, 4.07357859531773, 4.09364548494983, 4.11371237458194, 4.13377926421405, 4.15384615384615, 4.17391304347826, 4.19397993311037, 4.21404682274248, 4.23411371237458, 4.25418060200669, 4.27424749163880, 4.29431438127090, 4.31438127090301, 4.33444816053512, 4.35451505016722, 4.37458193979933, 4.39464882943144, 4.41471571906355, 4.43478260869565, 4.45484949832776, 4.47491638795987, 4.49498327759197, 4.51505016722408, 4.53511705685619, 4.55518394648829, 4.57525083612040, 4.59531772575251, 4.61538461538462, 4.63545150501672, 4.65551839464883, 4.67558528428094, 4.69565217391304, 4.71571906354515, 4.73578595317726, 4.75585284280936, 4.77591973244147, 4.79598662207358, 4.81605351170569, 4.83612040133779, 4.85618729096990, 4.87625418060201, 4.89632107023411, 4.91638795986622, 4.93645484949833, 4.95652173913044, 4.97658862876254, 4.99665551839465, 5.01672240802676, 5.03678929765886, 5.05685618729097, 5.07692307692308, 5.09698996655518, 5.11705685618729, 5.13712374581940, 5.15719063545151, 5.17725752508361, 5.19732441471572, 5.21739130434783, 5.23745819397993, 5.25752508361204, 5.27759197324415, 5.29765886287625, 5.31772575250836, 5.33779264214047, 5.35785953177258, 5.37792642140468, 5.39799331103679, 5.41806020066890, 5.43812709030100, 5.45819397993311, 5.47826086956522, 5.49832775919732, 5.51839464882943, 5.53846153846154, 5.55852842809365, 5.57859531772575, 5.59866220735786, 5.61872909698997, 5.63879598662207, 5.65886287625418, 5.67892976588629, 5.69899665551839, 5.71906354515050, 5.73913043478261, 5.75919732441472, 5.77926421404682, 5.79933110367893, 5.81939799331104, 5.83946488294314, 5.85953177257525, 5.87959866220736, 5.89966555183946, 5.91973244147157, 5.93979933110368, 5.95986622073579, 5.97993311036789, 6.;
sins << 0., 0.0205663230027132, 0.0390160433647213, 0.0590891330065624, 0.0875596988696830, 0.0959822118249474, 0.121373632487893, 0.144185779407900, 0.168823702943980, 0.195714802779603, 0.182086468335945, 0.208556236727609, 0.225094826864952, 0.239997837196716, 0.261856373004331, 0.285616850959075, 0.307675255212350, 0.368369766783931, 0.323959067443884, 0.384881639934677, 0.363815465411856, 0.447469201284049, 0.453774250363027, 0.430583512112867, 0.443099359428671, 0.509029695458685, 0.475835951758427, 0.535054453990577, 0.517313698480048, 0.540962965727346, 0.545515801814871, 0.549079158057189, 0.608171721462356, 0.633254366558289, 0.661681941754734, 0.621837761755506, 0.716087740139810, 0.626367576826244, 0.655836894152803, 0.686777150859095, 0.783641511917343, 0.740251957156445, 0.687992462634859, 0.784761727801862, 0.812689567708724, 0.723454299040675, 0.867775567606339, 0.834921353384008, 0.886473449480867, 0.829994027552906, 0.936539227083496, 0.878125359050542, 0.857422602795660, 0.797532129862921, 0.943697646147127, 0.931398718818189, 0.831954959636186, 0.990429183436099, 0.937267902704322, 1.03366330075745, 0.934498869672776, 1.03339624571952, 0.997468793041113, 1.06835135036732, 0.935065588934669, 1.05824035228952, 0.900356286901882, 1.10344335276178, 1.08109260151034, 1.00924107228951, 0.894536706478818, 1.05842262698500, 0.869469062376110, 1.10339186007555, 1.12123314842733, 0.898684459599225, 1.07266484712897, 1.08181878008800, 0.859772954875467, 1.05813887444340, 0.927536817088291, 1.05875873937114, 1.05513797051990, 0.881028526179104, 0.940789571986141, 0.939650398904516, 0.895333225658922, 1.15791888887766, 0.819811378153096, 0.872483401229913, 0.913929786309735, 1.07742711882579, 0.948836532262710, 1.01695652247989, 1.07892353697484, 1.07951455459521, 0.926555376069836, 0.796683097955963, 0.971180186596668, 1.08404809595985, 0.938788138021134, 0.723978021690113, 0.845028175059507, 0.827345363692465, 0.963611479800734, 0.784913093396594, 0.902260395754080, 0.754290064829049, 0.640991769001049, 0.840961782568416, 0.884688925819984, 0.945578335759086, 0.734722787877624, 0.730891994457772, 0.560468510656587, 0.888009033487127, 0.588779454127353, 0.507860660213622, 0.723119729832821, 0.706654621382516, 0.852209479056328, 0.441125081583452, 0.703532575135291, 0.649072175609160, 0.768270742631807, 0.821436286437389, 0.812472042863249, 0.310112243913094, 0.290088866876053, 0.784062286903034, 0.724847602437022, 0.382946261736111, 0.333365214123254, 0.255326531995527, 0.510563540394420, 0.546504484804774, 0.561758001362831, 0.193398150326653, 0.211822141863330, 0.337944053003746, 0.0491697943148871, 0.506909715390791, 0.394250155597078, 0.344556489656333, 0.220319484594126, 0.466870975203072, 0.352811824041645, -0.0203204635966194, 0.000187284360740975, 0.390929784556070, -0.0636185847381180, 0.215749967807034, 0.391783875224768, 0.0131507101596210, 0.214743651863588, 0.313117360143471, -0.213347879945078, -0.152700491575586, 0.284183282760694, 0.230258633151635, -0.170326153940235, -0.138941908793679, -0.361493597493055, 0.0225982276008491, 0.136956358471678, -0.0134364651061402, -0.354908737138856, -0.338680251031658, -0.324487377118159, -0.250495042710380, -0.207682989113764, -0.201777395597538, -0.603650467101997, -0.0570224603490521, -0.494298935449787, -0.701565642803869, -0.199839524611218, -0.548524440885001, -0.336774711215616, -0.663082614278816, -0.665924584060438, -0.558180481080407, -0.709519401338939, -0.550362969544220, -0.317669574094212, -0.215362655162646, -0.557314553299032, -0.476358803662329, -0.618538714302365, -0.857936707662719, -0.650422788916676, -0.450608748642427, -1.03675737413944, -0.458466487973903, -0.435238631393051, -0.612515366468904, -1.02282034118212, -1.00591774855133, -0.754300354448578, -0.811106583146996, -0.977243563786221, -1.15873641827749, -0.967899906565075, -0.603952304631890, -0.614897411289103, -0.506405816692878, -1.08323303849733, -0.878993651876167, -1.21339204205580, -0.926163267157209, -1.14708966655702, -0.702523099754653, -0.997607886250364, -1.05378691425895, -0.520207754254763, -1.22657313553732, -0.972570592572648, -1.16907062433655, -0.906452454632314, -1.03946558253614, -0.550998692611392, -1.08167304585878, -0.897951496093406, -0.780087992998209, -1.05605506303820, -0.726866824733939, -1.09042965985860, -1.38018514904770, -0.950070929813976, -1.05770071443760, -1.07268971722784, -0.543996855503508, -0.606425043418392, -0.945835692115167, -0.669056893514066, -1.16728466807845, -0.938678055549470, -1.01236119569040, -0.725637220253413, -0.878964985274675, -0.938002625674076, -1.29352679841118, -1.12194428508496, -1.36126581275738, -0.535406897512086, -1.11461313522307, -1.26469342269406, -1.35376389844295, -0.853393422301156, -1.23411956192447, -0.889103354650984, -0.453241720722455, -0.674642312393962, -0.485956820045976, -1.34342137994975, -0.522858292122314, -1.28347238567162, -0.991285795882105, -0.837456034504287, -1.02889729768886, -0.547777267737865, -0.385836799097512, -0.618013718429130, -1.03722116318478, -0.872749491150546, -1.10717663074987, -0.974662603291053, -1.11073176801917, -0.356460205615645, -0.954131536713498, -0.953578387057411, -0.408819629096933, -1.20503187990326, -0.823728061276806, -0.639337429057833, -0.865717404705197, -0.431884787539002, -1.01026779136354, -0.756675282804455, -1.10586000122177, -0.662224314038648, -0.111456991937247, -0.769480559944682, -0.0502235743017712, -0.584109125124463, -0.902892919532128, -0.466296466268305, -0.357583159307505, -0.472303230829483, -0.482252751675765, -0.497157767695055, 0.0271725486596654, -0.370289805051389, -0.403480529070726, 0.205775238849162, -0.736735702304588, -0.668465354498537, -0.0640652586715190, -0.284538180097004, -0.156691852132801;
Eigen::Spline<double, 1,4> spline(Eigen::SplineFitting<Eigen::Spline<double, 1,4>>::Interpolate(sins, 4, times));
for (int i = 0+4; i < size-4; i++)
{
std::cout << times(i) << "\t" << spline(times(i)) << "\t" << sins(i) << "\n";
}
return 0;
}