Source code :
clc;
disp ('====================================')
disp ('== Nama : Desianny Amalia Fauziah ==')
disp ('== NIM : 5302413085 ===============')
disp ('========== PTIK Rombel 2 ===========')
disp ('====================================')
x = [-1 : 0.2 : 1];
s = length(x);
d = zeros (1, s);
for i = 1 : s,
y (i) = ((sin((pi*x(i))/2)).^2);
d(:,i)=y(i);
end
a=x;
b=d;
fprintf('x :');
fprintf('%12.6f',a);
fprintf('\n');
fprintf('y :');
fprintf('%12.6f',b);
fprintf('\n');
cari=0.85;
s=11;
%%disp('iter x y')
for i=1:11;
sb(i,1)=y(i); %% sb = y
%% fprintf('%d %12.6f %12.6f\n',i,x,sb)
end
for i=2:s;
for j=1:s-i+1;
sb(j,i)=(sb(j+1,i-1)-sb(j,i-1))/(x(j+i-1)-x(j));
end
end
jumlah = sb(1,1);
for i=2:s;
z=sb(1,i);
for j=1:(i-1);
z=z*(cari-x(j));
end
jumlah=jumlah+z;
a=jumlah; %% interpolasi linear
end
disp('Interpolasi Polinom')
disp(['Nilai y (',num2str(cari),') = ', num2str(a)])
plot (x,y)
Tidak ada komentar:
Posting Komentar