资源简介
在matlab中实现三次样条插值,在周期边界条件下,以龙格函数为例。
代码片段和文件信息
function y=cubicspline3(x)
%第三类周期边界条件下三次样条插值;
%x = linspace(-1140);
%x所求点;
%y所求点函数值;
%x0 已知插值点;
%y0 已知插值点函数值;
%f_0左端点一次导数值;
%f_n右端点一次导数值;
x0 = linspace(02*pi20);
y0=sin(x0);
n = length(x0);
z = length(y0);
h = zeros(n-11);
k=zeros(n-21);
l=zeros(n-21);
S=2*eye(n);
for i=1:n-1
h(i)= x0(i+1)-x0(i);
end
for i=1:n-2
k(i)= h(i+1)/(h(i+1)+h(i));
l(i)= 1-k(i);
end
%对于第一种边界条件:
k = [0;k];
l = [l;0];
%构建系数矩阵A:
for i = 1:n-1
S(ii+1) = k(i);
S(i+1i) = l(i);
end
S(2n)=S(21);
S(21)=0;
S(n2)=h(1)/(h(1)+h(n-1));
S(nn-1)=h(n-1)/(h(1)+h(n-1));
%建立均差表:
F=zeros(n-12);
for i = 1:n-1
F(i1) = (y0(i+1)-y0(i))/(x0(i+1)-x0(i));
end
D = zeros(n-21);
for i = 1:n-2
F
评论
共有 条评论