Вы находитесь на странице: 1из 6

Desan Rafsanjani

1606826893
Tugas Interpolasi

17.11 The following data for the density of nitrogen gas versus temperature come from a table
that was measured with high precision. Use first – through fifth- order polynomials to estimate
the density at temperature of 330 K. What is your best estimate? Employ this best estimate and
inverse interpolation to determine the corresponding temperature.
K 200 250 300 350 400 450
Density, 1.708 1.367 1.139 0.967 0.854 0.759
3
Kg/m

Answer:

1. Hasil Script:

% Latihan Tugas Interpolasi


% oleh Desan Rafsanjani
% 7, Maret 2018
% =================================

clear all;
close all;

x =[200 250 300 350 400 450]


x0=x(:,1)
x1=x(:,2)
x2=x(:,3)
x3=x(:,4)
x4=x(:,5)
x5=x(:,6)

a =[1.708 1.367 1.139 0.967 0.854


0.759]; a0=a(:,1)
a1=a(:,2)
a2=a(:,3)
a3=a(:,4)
a4=a(:,5)
a5=a(:,6)

%xt adlah nilai yang ingin kita tebak


xt=330
%pendekatan orde 1
p1=a0+a1.*(xt-x0)
p2=a0+a1.*(xt-x0)+a2.*(xt-x0).*(xt-x1)
p3=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)
p4=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(x-
x0).*(x-x1).*(x-x2).*(x-x3)
p5=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(x-
x0).*(x-x1).*(x-x2).*(x-x3)+a5.*(x-x0).*(x-x1).*(x-x2).*(x-x3).*(x-x4)

%tahap ke 2 menggambar grafik


figure(1)
p11=a0+a1.*(x-x0)
plot(x,p11);
xlabel('nilai x');
ylabel('nilai f(x)');
title('Grafik Interpolasi')
grid on
hold on
plot(xt,p1,'ob','markersize',10,'markerfacecolor','r')

figure(2)
p22=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)
plot(x,p22);
grid on hold on
plot(xt,p2,'ob','markersize',10,'markerfacecolor','r')

figure(3)
p33=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)
plot(x,p33);
grid on
hold on
plot(xt,p3,'ob','markersize',10,'markerfacecolor','r')

figure(4)
p44=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(x-
x0).*(x-x1).*(x-x2).*(x-x3)
plot(x,p44);
grid on
hold on
plot(xt,p4,'ob','markersize',10,'markerfacecolor','r')

figure(5)
p55=a0+a1.*(x-x0)+a2.*(x-x0).*(x-x1)+a3.*(x-x0).*(x-x1).*(x-x2)+a4.*(x-
x0).*(x-x1).*(x-x2).*(x-x3)+a5.*(x-x0).*(x-x1).*(x-x2).*(x-x3).*(x-x4)
plot(x,p55);
grid on hold on
plot(xt,p5,'ob','markersize',10,'markerfacecolor','r')
2. Hasil screenshoot command window
3. Hasil Grafik

Вам также может понравиться