Senin, 09 Juni 2014

Matriks Tridiagonal pada Metode Numerik






Algoritma Program Pascal untuk Matriks Tridiagonal pada Metode Numerik
program Tridiagonal;
uses wincrt;
var
   i, j, k, n : integer;
   p          : real;
   a          : array[0..20] of real;
   b          : array[0..20] of real;
   c          : array[0..20] of real;
   d          : array[0..20] of real;
   e          : array[0..20,0..20] of real;
   x          : array[0..20] of real;

label 1, 2, 3, 4, 5;

begin
1:
  writeln('Orde matriks anda(maksimal 20x20): ');readln(n);
  {Penginputan elemen-elemen matriks}
  for i:= 1 to n do
      begin
           write('a',i,' = ');readln(a[i]);
      end;
  for i:= 1 to n-1 do
      begin
           write('b',i,' = ');readln(b[i]);
      end;
  for i:= 2 to n do
      begin
           write('c',i,' = ');readln(c[i]);
      end;
  for i:= 1 to n do
      begin
           write('d',i,' = ');readln(d[i]);
      end;
  {Pencetakan matriks tridiagonal}
  clrscr;
  writeln('Matriks anda:');
  for i:= 1 to n do
      begin
           e[i,i]:= a[i];
           e[i,i+1]:= b[i];
           e[i,i-1]:= c[i];
      end;
  for i:= 1 to n do
      begin
           write('|');
           for j:= 1 to n do
               begin
                    write(' ',e[i,j]:0:4);
               end;
           writeln(' ',d[i]:0:4,' |');
      end;

  writeln('');
  writeln('Akar-akarnya:');
  {Proses SPL tridiagonal}
  for i:= 1 to n-1 do
      begin
           p:= c[i+1]/a[i];
           a[i+1]:= a[i+1] - p*b[i];
           d[i+1]:= d[i+1] - p*d[i];
      end;

  x[n]:= d[n]/a[n];
  writeln('x',n,' = ',x[n]:0:4);

  for k:= n-1 downto 1 do
      begin
           x[k]:= (d[k]-b[k]*x[k+1])/a[k];
           writeln('x',k,' = ',x[k]:0:4);
      end;
end.


Preview Program:

Tidak ada komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...