cscvn of a function, coefficients and breaks

조회 수: 2 (최근 30일)
David
David 2014년 7월 9일
편집: Bruno Luong 2023년 11월 24일
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
Lucie
Lucie 2023년 11월 24일
Hello, I am facing the same issue. Did you receive an answer regarding the meaning of the coefficients?

댓글을 달려면 로그인하십시오.

답변 (1개)

Bruno Luong
Bruno Luong 2023년 11월 24일
편집: Bruno Luong 2023년 11월 24일
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

카테고리

Help CenterFile Exchange에서 Spline Construction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by