spapi: why slvblk instead of backslash operator?
Afficher commentaires plus anciens
% data
x = [3.0,4.5,6.0,7.5,9.0,12.0,15.0];
y = [0 0.0343653 0.0694232 0.105143 0.141178 0.246013 0.630537];
xq = linspace(min(x), max(x), 1000);
[f, fd, fdd] = Evaluate_spline(xq, x, y, order);
% plotting (xq,f), ... gives the same curves as produced by spapi
function [yq, fd, fdd] = Evaluate_spline(xq, x, y, order)
t = aptknt(x, order);
A = spcol(t, order, x);
sol = A\y(:);
yq = 0;
fd = 0;
fdd = 0;
for i=1:numel(x)
spline = spmak(t(i:i+order), 1);
yq = yq + fnval(spline, xq) .* sol(i);
fd = fd + fnval(fnder(spline, 1), xq) .* sol(i);
fdd = fdd + fnval(fnder(spline, 2), xq) .* sol(i);
end
end
However, in my code, I simply used "\" operator to solve the linear system for the control points whereas spapi is calling slvblk.
(1) Is that for reasons of efficiency when the number of data points becomes larger? Or are there other reasons and using backslash is not appropriate (inaccurate, unstable, ...) for some cases.
The reason to implement an own version is that I have to evaluate the spline at a large number of points which I know one-by-one at runtime. If I am not mistaken, calling fnval(spline, x) uses the De Boor's algorithm (recursion). Are there better ways for frequent evaluations of a spline?
Thank you!
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spline Postprocessing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!