【matlab】绘制双三次插值函数曲线

时间:2024-10-29 17:35:56

想要的效果:

【matlab】绘制双三次插值函数曲线

编程时要用到分段函数曲线的绘制方法:..+.*(分段条件)。

需要注意的是:函数表达式中的乘除和乘方都要加“.”。因为一般的函数都是数在乘变量运算。

x=-:0.001:;
a=-0.5;
w=abs(x);
y=(1.5.*w.^-2.5.*w.^+).*(w<=)+(-0.5.*w.^+2.5.*w.^-.*w+).*(w>&w<=);
plot(x,y);
box off;
view([ ]);
xlabel('w');
ylabel('S(w)');

【matlab】绘制双三次插值函数曲线

然后想将坐标轴变一下:

新建一个xyplot.m文件:

function xyplot(x,y)
% xyplot Plot 2D axes through the origin
% Example :
% t = linspace(,*pi,);
% y1 = *sin(t);
% y2 = *cos(t);
% xyplot(t,[y1;y2])
%
% Example :
% x = -*pi:pi/:*pi;
% y = sin(x);
% plot(x,y)
% xyplot
% PLOT
if nargin>
if nargin ==
plot(x,y);
else
display('Not 2D Data set!')
end
end
hold on;
% GET TICKS
X=get(gca,'Xtick');
Y=get(gca,'Ytick');
% GET LABELS
XL=get(gca,'XtickLabel');
YL=get(gca,'YtickLabel');
% GET OFFSETS
Xoff=diff(get(gca,'XLim'))./;
Yoff=diff(get(gca,'YLim'))./;
% DRAW AXIS LINEs
plot(get(gca,'XLim'),[ ],'k');
plot([ ],get(gca,'YLim'),'k');
% Plot new ticks
for i=:length(X)
plot([X(i) X(i)],[ Yoff],'-k');
end;
for i=:length(Y)
plot([Xoff, ],[Y(i) Y(i)],'-k');
end;
% ADD LABELS
text(X,zeros(size(X))-.*Yoff,XL);
text(zeros(size(Y))-.*Xoff,Y,YL);
box off;
% axis square;
axis off;
set(gcf,'color','w');

重新调用运行即可:

x=-:0.001:;
a=-0.5;
w=abs(x);
y=(1.5.*w.^-2.5.*w.^+).*(w<=)+(-0.5.*w.^+2.5.*w.^-.*w+).*(w>&w<=);
xyplot(x,y);

【matlab】绘制双三次插值函数曲线