کد متلب (MATLAB) : مثال شماره 7
کدهای متلب :
clear all
close all
clc
% Interactive script to fit a cubic to data points
clf
hold on
axis([0 100 0 100]);
diff = 10;
xold = 68;
i = 0;
xp = zeros(1); % data points
yp = zeros(1);
while diff > 2
[a b] = ginput(1);
diff = abs(a - xold);
if diff > 2
i = i + 1;
xp(i) = a;
yp(i) = b;
xold = a;
plot(a, b, 'ok')
end
end
p = polyfit(xp, yp, 3 );
x = 0:0.1:xp(length(xp));
y= p(1)*x.^3 + p(2)*x.^2 + p(3)*x + p(4);
plot(x,y), title( 'cubic polynomial fit'), ...
ylabel('y(x)'), xlabel('x')
hold off
close all
clc
% Interactive script to fit a cubic to data points
clf
hold on
axis([0 100 0 100]);
diff = 10;
xold = 68;
i = 0;
xp = zeros(1); % data points
yp = zeros(1);
while diff > 2
[a b] = ginput(1);
diff = abs(a - xold);
if diff > 2
i = i + 1;
xp(i) = a;
yp(i) = b;
xold = a;
plot(a, b, 'ok')
end
end
p = polyfit(xp, yp, 3 );
x = 0:0.1:xp(length(xp));
y= p(1)*x.^3 + p(2)*x.^2 + p(3)*x + p(4);
plot(x,y), title( 'cubic polynomial fit'), ...
ylabel('y(x)'), xlabel('x')
hold off
نتیجه :
منبع کدها :
کتاب Essential MATLAB for Engineers and Scientists - صفحه 406 از فایل pdf کتاب
دسته بندی
انواع رسم شکل در متلب
نظرات 0 0 0