SELAMAT DATANG

INTERPOLASI polynomial

clc
clear all
x1=3.2; y1=22;
x2=2.7; y2=17.8;
x3=1;   y3=14.2;
x4=4.8; y4=38.3;
x5=5.6; y5=51.7;
X=[x1^0 x1^1 x1^2 x1^3 x1^4;x2^0 x2^1 x2^2 x2^3 x2^4;x3^0 x3^1 x3^2 x3^3 x3^4;x4^0 x4^1 x4^2 x4^3 x4^4;x5^0 x5^1 x5^2 x5^3 x5^4];
Y=[y1;y2;y3;y4;y5];
A=X\Y;
fprintf('Y = %5.2fx^0 + %5.2fx^1 + %5.2fx^2 + %5.2fx^3 + %5.2fx^4 \n',A(1),A(2),A(3),A(4),A(5))
disp('================')
disp(' i     x      y ')
disp('================')
x=3;
for i=1:20
    y=A(1)*x^0+A(2)*x^1+A(3)*x^2+A(4)*x^3+A(5)*x^4;
    fprintf('%3g %5.2f %5.2f \n',i,x,y)
    x=x+1;
end

0 komentar:

Posting Komentar

Flag Counter