1. The fitted curve passes through discrete path points
x= [0;0.0128205128205128;0.0256410256410256;0.0384615384615385;0.0512820512820513;0.0641025641025641;0.0769230769230769;0.0897435897435897;0.102564102564103;0.115384615384615;0.128205128205128;0.141025641025641;0.153846153846154;0.166666666666667;0.179487179487180;0.192307692307692;0.205128205128205;0.217948717948718;0.230769230769231;0.243589743589744;0.256410256410256;0.269230769230769;0.282051282051282;0.294871794871795;0.307692307692308;0.320512820512821;0.333333333333333;0.346153846153846;0.358974358974359;0.371794871794872;0.384615384615385;0.397435897435897;0.410256410256410;0.423076923076923;0.435897435897436;0.448717948717949;0.461538461538462;0.474358974358974;0.487179487179487;0.500000000000000;0.512820512820513;0.525641025641026;0.538461538461538;0.551282051282051;0.564102564102564;0.576923076923077;0.589743589743590;0.602564102564103;0.615384615384615;0.628205128205128;0.641025641025641;0.653846153846154;0.666666666666667;0.679487179487180;0.692307692307692;0.705128205128205;0.717948717948718;0.730769230769231;0.743589743589744;0.756410256410256;0.769230769230769;0.782051282051282;0.794871794871795;0.807692307692308;0.820512820512821;0.833333333333333;0.846153846153846;0.858974358974359;0.871794871794872;0.884615384615385;0.897435897435898;0.910256410256410;0.923076923076923;0.935897435897436;0.948717948717949;0.961538461538462;0.974358974358974;0.987179487179487;1]
y = [0;0;-0.00210988000000000;-0.00115278000000000;-0.000152780000000000;0.00281970000000000;0.00381978000000000;0.00483972000000000;0.00793453000000000;0.0115414000000000;0.0133153000000000;0.0146549000000000;0.0157498000000000;0.0166018000000000;0.0172609000000000;0.0176989000000000;0.0179270000000000;0.0179989000000000;0.0179386000000000;0.0178000000000000;0.0176083000000000;0.0174145000000000;0.0172459000000000;0.0171472000000000;0.0171085000000000;0.0171238000000000;0.0171999000000000;0.0173190000000000;0.0174359000000000;0.0175483000000000;0.0176107000000000;0.0175886000000000;0.0174669000000000;0.0172009000000000;0.0166578000000000;0.0158427000000000;0.0146909000000000;0.0132764000000000;0.0114232000000000;0.00985331000000000;0.00798939000000000;0.00573892000000000;0.00300738000000000;0;-0.00443505000000000;-0.00944156000000000;-0.0155150000000000;-0.0228853000000000;-0.0318467000000000;-0.0427468000000000;-0.0560513000000000;-0.0721688000000000;-0.0913496000000000;-0.113515000000000;-0.137977000000000;-0.162830000000000;-0.185098000000000;-0.201125000000000;-0.207564000000000;-0.203193000000000;-0.189337000000000;-0.169244000000000;-0.146676000000000;-0.123783000000000;-0.102184000000000;-0.0817261000000000;-0.0612605000000000;-0.0395437000000000;-0.0159423000000000;0.00880633000000000;0.0333237000000000;0.0563616000000000;0.0781288000000000;0.101801000000000;0.130293000000000;0.157632000000000;0.171608000000000;0.180132000000000;0.172427000000000]
sp = spapi(3,x,y);
fnplt(sp);
Among them: (x, y) are discrete data points; spapi(3, x, y) means to fit discrete data points with a third-order B-spline curve, and to pass through the given discrete data points; fnplt( sp) represents drawing the B-spline curve.
The result is as follows:
2. The fitted curve is smoothed but not necessarily past the data points
x= [0;0.0128205128205128;0.0256410256410256;0.0384615384615385;0.0512820512820513;0.0641025641025641;0.0769230769230769;0.0897435897435897;0.102564102564103;0.115384615384615;0.128205128205128;0.141025641025641;0.153846153846154;0.166666666666667;0.179487179487180;0.192307692307692;0.205128205128205;0.217948717948718;0.230769230769231;0.243589743589744;0.256410256410256;0.269230769230769;0.282051282051282;0.294871794871795;0.307692307692308;0.320512820512821;0.333333333333333;0.346153846153846;0.358974358974359;0.371794871794872;0.384615384615385;0.397435897435897;0.410256410256410;0.423076923076923;0.435897435897436;0.448717948717949;0.461538461538462;0.474358974358974;0.487179487179487;0.500000000000000;0.512820512820513;0.525641025641026;0.538461538461538;0.551282051282051;0.564102564102564;0.576923076923077;0.589743589743590;0.602564102564103;0.615384615384615;0.628205128205128;0.641025641025641;0.653846153846154;0.666666666666667;0.679487179487180;0.692307692307692;0.705128205128205;0.717948717948718;0.730769230769231;0.743589743589744;0.756410256410256;0.769230769230769;0.782051282051282;0.794871794871795;0.807692307692308;0.820512820512821;0.833333333333333;0.846153846153846;0.858974358974359;0.871794871794872;0.884615384615385;0.897435897435898;0.910256410256410;0.923076923076923;0.935897435897436;0.948717948717949;0.961538461538462;0.974358974358974;0.987179487179487;1]
y = [0;0;-0.00210988000000000;-0.00115278000000000;-0.000152780000000000;0.00281970000000000;0.00381978000000000;0.00483972000000000;0.00793453000000000;0.0115414000000000;0.0133153000000000;0.0146549000000000;0.0157498000000000;0.0166018000000000;0.0172609000000000;0.0176989000000000;0.0179270000000000;0.0179989000000000;0.0179386000000000;0.0178000000000000;0.0176083000000000;0.0174145000000000;0.0172459000000000;0.0171472000000000;0.0171085000000000;0.0171238000000000;0.0171999000000000;0.0173190000000000;0.0174359000000000;0.0175483000000000;0.0176107000000000;0.0175886000000000;0.0174669000000000;0.0172009000000000;0.0166578000000000;0.0158427000000000;0.0146909000000000;0.0132764000000000;0.0114232000000000;0.00985331000000000;0.00798939000000000;0.00573892000000000;0.00300738000000000;0;-0.00443505000000000;-0.00944156000000000;-0.0155150000000000;-0.0228853000000000;-0.0318467000000000;-0.0427468000000000;-0.0560513000000000;-0.0721688000000000;-0.0913496000000000;-0.113515000000000;-0.137977000000000;-0.162830000000000;-0.185098000000000;-0.201125000000000;-0.207564000000000;-0.203193000000000;-0.189337000000000;-0.169244000000000;-0.146676000000000;-0.123783000000000;-0.102184000000000;-0.0817261000000000;-0.0612605000000000;-0.0395437000000000;-0.0159423000000000;0.00880633000000000;0.0333237000000000;0.0563616000000000;0.0781288000000000;0.101801000000000;0.130293000000000;0.157632000000000;0.171608000000000;0.180132000000000;0.172427000000000]
w = ones(size(x)); w([1 end]) = 100;
sp = spaps(x,y, 1.e-2, w, 3);
fnplt(sp);
Among them: (x, y) are discrete data points; spaps (x, y, 1.e-2, w, 3) means to use B-spline curve to smoothly fit discrete data points, not necessarily through a given For discrete data points, 1.e-2 is the allowable fitting error, the first and last components of the w vector are 100, and the rest are 1, which means that the starting point and ending point after fitting must be very close to the data point.
The result is as follows:
From the lowest point of the curve, it can be seen that there is a large deviation from the original data point.
If you change 1.e-2 to 1.e-5, you can get: It
can be seen that the above figure is closer to the original data point.
Attachment: Spline Toolbox Function
-
Cubic spline function
csapi interpolation generates cubic spline function csape generates cubic spline function
csaps under given constraints
smoothly generates cubic spline function
cscvn generates a cubic spline curve with interpolation parameters
getcurve dynamically generates cubic spline curve -
Piecewise polynomial spline function
ppmak Generates piecewise polynomial spline function
ppual Calculates the value of the piecewise polynomial spline function at a given point -
B-spline function
spmak generates B-spline function
spcrv generates uniformly divided B-spline function
spapi interpolation generates B-spline function
spap2 uses least squares fitting to generate B-spline function
spaps Smooth the generated B-spline curve
spcol Generate configuration matrix of B-spline function -
Rational spline function
rpmak generates rational spline function
rsmak generates rational spline function -
The spline operation function
fnval calculates the value of the spline function at a given point
fmbrk returns a part of the spline function (such as breakpoints or coefficients, etc.)
fncmb performs arithmetic operations on the spline function
fn2fm converts a form of spline function into Another form of the spline function
fnder Differentiate the spline function (that is, find the derivative)
fndir Find the directional derivative of the
spline function fnint Find the integral of the spline function
fnjmp Find the function value at the discontinuous point
fnplt Draw the spline graph
fnrfn Insert a breakpoint in the spline curve.
fntlr generates tarylor coefficients or taylor polynomials -
Spline end point and node processing function
augknt Add one or more nodes
aveknt to the known node array to find the average value of the node array elements
brk2knt increase the node's repeat order
in the node array knt2brk to find the node and its weight from the node array The order
knt2mlt finds the nodes from the node array and their multiple
sorted finds the element of the node array belongs to which component in another node array
aptknt finds the node array
newknt used to generate the spline curve and the piecewise polynomial
Redistribute the strip function optknt Find the optimal node array for interpolation
chbpnt Find the appropriate node array for generating the spline