这是夹紧的三次样条代码,但在第一行(
n = length(X);
)标记错误,MATLAB说没有足够的输入参数,说实话,我不知道为什么。有人帮帮我。
function [a,b,c,d]=ClampedCubicSpline(X,a,FPO,FPN)
n = length(X);
m = length (a);
for i=1:n;
a(i)=X(2,i);
end
for i=1:n-1;
h(i)=X(1,i+1)-X(1,i);
end
alpha(1) = (3/hi(1))*(a(2)-a(1)) - 3 * FPO;
alpha(n) = 3*FPN - (3/hi(n-1))*(a(n)-a(n-1));
for i=2:n-1;
alpha(i)=3/h(i)*(a(i+1)-a(i))-3/h(i-1)*(a(i)-a(i-1));
end
l(1)=2*h(1);
mu(1)=.5;
z(1)=alpha(1)/l(1);
for i=2:n-1;
l(i)=2*(X(1,i+1)-X(1,i-1))-h(i-1)*mu(i-1);
mu(i)=h(i)/l(i);
z(i)=(alpha(i)-h(i-1)*z(i-1))/l(i);
end
l(n)=h(n-1)*(2-mu(n-1));
z(n)=(alpha(n)-h(n-1)*z(n-1))/l(n);
c(n)=z(n);
for i=n-1:-1:1;
c(i)=z(i)-mu(i)*c(i+1);
b(i)=(a(i+1)-a(i))/h(i)-h(i)*(c(i+1)+2*c(i))/3;
d(i)=(c(i+1)-c(i))/(3*h(i));
end
for i=1:n-1;
x=X(1,i):0.1:X(1,i+1);
y=a(i)+b(i)*(x-X(1,i))+c(i)*(x-X(1,i)).^2+d(i)*(x-X(1,i)).^3;
hold on;
plot(x,y,'b');
end