Selasa, 03 Juni 2014

Interpolasi Lagrange pada Metode Numerik

Algoritma program Pascal interpolasi Lagrange
program Interpolasi_Lagrange;
uses wincrt;
var
   i, j, n          : integer;
   z, faktor, plag  : real;
   x, y             : array[0..100] of real;
label 1, 2, 3;

begin
1:
  write('Titik dicari: ');readln(z);
  write('n         = ');readln(n);
  writeln('===============================');
  writeln('Titik dan nilai diketahui:');
  for i:= 0 to n do
  begin
       write('   Untuk x',i,' = ');readln(x[i]);
       write('         f(',x[i]:0:2,') = ');readln(y[i]);
  end;
  writeln('===============================');


  plag:= 0;
  for i:= 0 to n do
  begin
       faktor:= 1;
       for j:= 0 to n do
       begin
            if j <> i then faktor:= faktor*((z - x[j])/(x[i] - x[j]));
       end;
       plag:= plag + faktor*y[i];
  end;

  writeln('Jadi f(',z:0:2,') = ',plag:0:6);
end.


Preview program:

Download program: klik disini

Tidak ada komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...