Senin, 09 Juni 2014

Regresi Linier pada Metode Numerik

Algoritma Program Pascal untuk Regresi Linier pada Metode Numerik
program Regresi_Linier;
uses wincrt;
var
   i, j, n                        : integer;
   a, b, jumx, jumx2, jumy, jumxy : real;
   x, y                           : array[1..100] of real;
label 1, 2, 3;

begin
1:
  write('Banyak data = ');readln(n);
  for i:= 1 to n do
      begin
           write('Masukkan x',i,' = ');readln(x[i]);
           write('Masukkan y',i,' = ');readln(y[i]);
      end;


  jumx:= 0;
  jumy:= 0;
  jumxy:= 0;
  jumx2:= 0;
  for i:= 1 to n do
      begin
           jumx:= jumx + x[i];
           jumy:= jumy + y[i];
           jumxy:= jumxy + x[i]*y[i];
           jumx2:= jumx2 + x[i]*x[i];
      end;

  b:= (n*jumxy - jumx*jumy)/(n*jumx2 - jumx*jumx);
  a:= (jumy - b*jumx)/n;
  writeln;                                                                                     
  write('sigma xi = ',jumx:0:6);
  writeln('      sigma yi = ',jumy:0:6);
  write('sigma xiyi = ',jumxy:0:6);
  writeln('   sigma (xi)kuadrat = ',jumx2:0:6);
  writeln;
  writeln('Jadi persamaannya adalah g(x) = ',a:0:6,' + ',b:0:6,'x');
end.


Preview Program:

Tidak ada komentar:

Posting Komentar

Related Posts Plugin for WordPress, Blogger...