Cubic Spline Function help
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I need to develop a function file [y]=Spline_Clamped(x,f,xi) that can be used to find the function value y for a given xi. I need to apply the function to a data table to generate a plot.
Data Table: Xi=[3.0,4.5,7,9] fi=[2.5,1.0,2.5,0.5] This is what I have so far:
function[y]=Spline_Clamped(x,f,xi)
x=A(:,1);
f=A(:,2);
n=length(x);
b=zeros(n,1); c=zeros(n,1); d=zeros(n,1);
h=zeros(n,1);
a=f;
for i=1:n-1
h(i)=x(i+1)-x(i);
end
BB=zeros(n,n);
rr=zeros(n,1);
BB(1,1)=h(2);
BB(1,2)=-(h(1)+h(2));
BB(1,3)=h(1);
for i=2:n-1
BB(i,i-1)=h(i-1);
BB(i,i)=2*(h(i-1)+h(i));
BB(i,i+1)=h(i);
rr(i)=3*(f(i+1)-f(i))/h(i)-3*(f(i)-f(i-1))/h(i-1);
end
BB(n,n-2)=h(n-1);
BB(n,n-1)=-(h(n-2)+h(n-1));
BB(n,n)=h(n-2);
c=BB\rr;
for i=1:n-1
d(i)=(c(i+1)-c(i))/3/h(i);
b(i)=(f(i+1)-f(i))/h(i)-h(i)/3*(2*c(i)+c(i+1));
end
i_knot=[1:n]'
z=[i_knot a b c d]'
fprintf(' interval a_i b_i c_i d_i\n', z);
fprintf('%7d %12.4 %12.4 %12.4 %12.4 \n', z);
0 commentaires
Réponses (1)
Voir également
Catégories
En savoir plus sur Splines dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!