Selasa, 03 Juni 2014

Sistem Persamaan Linier Metode Jacobi pada Metode Numerik

Algoritma program Pascal pencarian solusi sistem persamaan linier metode Jacobi


program Jacobi_The_Queen_of_Science;

uses wincrt;

var

   i, j, k, n, cek, max     : integer;

   tolmin, tolmax, er       : real;

   a                        : array[0..20,0..20] of real;

   c                        : array[0..20] of real;

   x, xh                    : array[0..20] of real;



label 1, 2, 3, 4, 5;



begin

1:

  writeln('Orde matriks anda(maksimal 20x20): ');readln(n);clrscr;

  writeln('Tentukan toleransi maksimum anda: ');readln(tolmax);clrscr;

  writeln('Tentukan toleransi minimum anda: ');readln(tolmin);clrscr;

  writeln('Tentukan banyak iterasi yang anda inginkan: ');readln(max);clrscr;




  {Input elemen-elemen dan tebakan awal}

  writeln('Masukkan elemen-elemen matriks dan tebakan awal anda.');

  for i:= 1 to n do

      begin

           for j:= 1 to n do

               begin

                    write('a',i,'',j,' = ');readln(a[i,j]);

               end;

           write('Masukkan ruas kanan c',i,' = ');readln(c[i]);

           write('Masukkan tebakan awal x',i,' = ');readln(x[i]);

      end;

  clrscr;



  {Proses eliminasi dan pencetakan}

  writeln('                   Tabel');

  writeln('Iterasi       x1                   x2                   x3');



  for i:= 1 to n do

      begin

           write('   ',0,'     ',x[i]:0:10);

      end;

  writeln('');



  for k:= 1 to max do

  begin

       cek:= 0;

       for i:= 1 to n do

           begin

                xh[i]:= c[i];

                for j:= 1 to n do

                    begin

                         if j <> i then xh[i]:= xh[i] - a[i,j]*x[j];

                    end;



                xh[i]:= xh[i]/a[i,i];

                er:= abs(x[i] - xh[i]);

                if er < tolmin then cek:= cek + 1;

                if er > tolmax then

                   begin

                        writeln('Divergen!');goto 3;

                   end;

           end;

      for i:= 1 to n do

          begin

               x[i]:= xh[i];

               if k < 10 then write('   ',k,'     ',x[i]:0:10);

               if k >= 10 then

                  begin

                       if k < 100 then write('   ',k,'    ',x[i]:0:10);

                  end;

               if i = n then

                  begin

                       if cek = 3 then goto 2;

                  end;

          end;

      writeln;

  end;

  writeln('Proses belum konvergen.');goto 3;

2:

  {Cetak hasil jika ditemukan}

  writeln;

  writeln('Akar-akarnya adalah');

  for i:= 1 to n do

      begin

           write('          x',i,' = ',x[i]:0:4);

      end;

3:

end.



Preview program:

Download program: Klik Di sini

1 komentar:

  1. kak, ini berapa toleransi maks dan toleransi min nya kak ?

    BalasHapus

Related Posts Plugin for WordPress, Blogger...