📄 campare3inter.m
字号:
function result=campare3inter(count_knot,count_dot)
%count_knot
%count_dot
clf
knot=linspace(-2,2,count_knot+2);
x=-2:0.01:2;
y=exp(-x.^2);
y0=exp(-knot.^2);
plot(x,y,knot,y0,'ro');%,
hold on;
x_new=linspace(-2,2,count_dot);
y_real=exp(-x_new.^2);
%Lagrange
y_lagrange=lagrange(knot,y0,x_new);
plot(x_new,y_lagrange,'k');
hold on;
%divide
y_line=zeros(1,length(x_new));
count_1=1;
for j=1:count_dot
for i=1:count_knot+1
if((x_new(j)>=knot(i))&((x_new(j)<=knot(i+1))))
%
y_line(count_1)=((y0(i)-y0(i+1))/(knot(i)-knot(i+1)))*(x_new(j)-knot(i))+y0(i);
count_1=count_1+1;
break; end
end
end
plot(x_new,y_line,'b');
hold on;
%spline
y_temp=[0 y0 0];
pp=csape(knot,y_temp,'second');
[breaks,coefs,npolys,ncoefs,dim]=unmkpp(pp);
count=1;
for j=1:count_dot
for i=1:count_knot+1
if((x_new(j)>=knot(i))&((x_new(j)<=knot(i+1))))
y_spline(count)=polyval(coefs(i,:),x_new(j)-knot(i));
count=count+1;
break;
end
end
end
plot(x_new,y_spline,'g');
result=[y_real' y_lagrange' y_line' y_spline']
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -