کد متلب (MATLAB) : مثال شماره 17
کدهای متلب :
clear all
close all
clc
x = [0 pi/4 3*pi/8 3*pi/4 pi]; y = sin(x);
xi = linspace(0,pi,40)';
yn = interp1(x,y,xi,'nearest');
yl = interp1(x,y,xi,'linear');
ys = interp1(x,y,xi,'spline');
yp = interp1(x,y,xi,'pchip');
xx = linspace(0,pi,50);
plot(xi,yn,'*', xi,yl,'+', xi,ys,'v', xi,yp,'o')
legend('nearest','linear','spline','pchip')
hold on
plot(xx,sin(xx),'-',x,y,'.k','MarkerSize',30)
set(gca,'XTick',x), set(gca,'XTickLabel','0|pi/4l3pi/8|3pi/4|pi')
set(gca,'XGrid','on')
axis([-0.25 3.5 -0.1 1.1])
hold off
close all
clc
x = [0 pi/4 3*pi/8 3*pi/4 pi]; y = sin(x);
xi = linspace(0,pi,40)';
yn = interp1(x,y,xi,'nearest');
yl = interp1(x,y,xi,'linear');
ys = interp1(x,y,xi,'spline');
yp = interp1(x,y,xi,'pchip');
xx = linspace(0,pi,50);
plot(xi,yn,'*', xi,yl,'+', xi,ys,'v', xi,yp,'o')
legend('nearest','linear','spline','pchip')
hold on
plot(xx,sin(xx),'-',x,y,'.k','MarkerSize',30)
set(gca,'XTick',x), set(gca,'XTickLabel','0|pi/4l3pi/8|3pi/4|pi')
set(gca,'XGrid','on')
axis([-0.25 3.5 -0.1 1.1])
hold off
نتیجه :
منبع کدها :
کتاب MATLAB Guide - D.J. Higham - second edition - صفحه 163 از فایل pdf کتاب
دسته بندی
انواع رسم شکل در متلب
نظرات 0 0 0