# how can i work with the coefs of cscvn?

7 views (last 30 days)
Timon Niedecken on 6 Jun 2018
Commented: atharva aalok on 29 Aug 2022
Hi there, I use cscvn() from curve fitting toolbox to get a natural spline for n points. n > 1000 in my specific case. The result is a (2*n)x4 double array for the coefficients and an break array. Now i want to calculate the length and the curvature(t=t0) of the spline. I know there are some formulae for that, but i dont know how to combine the coefficients for each spline section. i tried to understand it with
edit cscvn
but failed :/

Unai San Miguel on 9 Jul 2018
There is no need to use the coefficients of the function, because the Curve Fitting Toolbox provides with functions to derive and evaluate the spline functions (curves).
The output of cscvn is a curve from R to R^d, being d the dimension of your points ([d, n] = size(points)|). The rth-derivative of that curve can be obtained with fnder(crv, r). It is also a spline function which can be evaluated with fnval(·, t) at any point you want (in the domain of your curve). So, if crv = cscvn(points), then the first derivative at t0 is fnval(fnder(crv,1), t0), the second derivative is fnval(fnder(crv, 2), t0) and so on. With these and the formulas from differential geometry of curves you can calculate the curvature of the spline.
To calculate the length of the spline you have to do the integral of the norm of the derivative
Dcrv = fnder(crv);
crvlength = integral(@(x) fnval(@(tau) sum(fnval(Dcrv, tau).^2), 1).^0.5, crv.breaks(1), crv.breaks(end));
atharva aalok on 29 Aug 2022
How can I make the curve smoother and also evaluate the curve for a given set of x values?
Please have a look at this question.