Filter löschen
Filter löschen

cscvn of a function, coefficients and breaks

5 Ansichten (letzte 30 Tage)
David
David am 9 Jul. 2014
Bearbeitet: Bruno Luong am 24 Nov. 2023
Hey all together,
I have another question concerning the cscvn function. When I create a spline for a function with cscvn
yy = cscvn(xges)
and take a look at yy.coefs and yy.breaks
form: 'pp'
breaks: [1x25 double]
coefs: [48x4 double]
pieces: 24
order: 4
dim: 2
then I have nearly twice as much coefs as breaks. How is this possible and what does that mean? How can I create the piecewise polynomial functions out of my coefs? At the end I want to calculate the curvature of the function, but first I have to understand what this coefs mean, and how I can create the piecewise polynoms.
Thank you in advance,
David
  2 Kommentare
Lucie
Lucie am 24 Nov. 2023
Hello, I am facing the same issue. Did you receive an answer regarding the meaning of the coefficients?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Bruno Luong
Bruno Luong am 24 Nov. 2023
Bearbeitet: Bruno Luong am 24 Nov. 2023
This is how to use pp
m = 2;
n = 5; % 25 in the original question
points = rand(m,n);
pp = cscvn(points)
pp = struct with fields:
form: 'pp' breaks: [0 0.8735 1.5529 2.4191 3.2527] coefs: [8×4 double] pieces: 4 order: 4 dim: 2
m = pp.dim;
p = pp.pieces;
% https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/INT-APP/PARA-centripetal.html
%D = diff(points,1,2);
%d = sqrt(sqrt(sum(D.^2,1)));
%t = cumsum([0 d]); % Eugene Lee's, equal to pp.breaks, see https://www.mathworks.com/help/curvefit/cscvn.html
t = pp.breaks;
ni = 200;
ti = linspace(t(1),t(end), ni);
loc = discretize(ti, t);
x = zeros(length(ti), m);
coefs = reshape(pp.coefs, m, p, []);
for k=1:p
ink = loc == k;
tik = ti(ink);
dti = tik - t(k);
for d=1:m
P = coefs(d, k, :);
x(ink,d) = polyval(P(:), dti);
end
end
close all
hold on
if m == 2
plot(points(1,:),points(2,:),'or'),
plot(x(:,1), x(:,2),'b.')
elseif m == 3
plot3(points(1,:),points(2,:),points(3,:),'or'),
plot3(x(:,1), x(:,2), x(:,3), 'b.')
else
warning('plotting not supported')
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by