Program Menghitung Koefisien Persamaan Regressi

Program Menghitung Koefisien Persamaan Regressi;
uses wincrt;
type data=array[1..100]of integer;
var
x,y :data;
N,d,j :Integer;
ratax,ratay :real;
SXY,SX,SX2,SY:real;
A,B :real;
{--------------------------------------------------------------------}
Procedure Regressi;
begin
N:=0;
repeat
write('Nilai data x= ');readln(d);
if d<>0 then begin
N:=N+1;
x[N]:=d;
write('Nilai data y = ');readln(y[N]);
end;
until d=0;
SXY:=0; SX:=0; SX2:=0; SY:=0;
for j:= 1 to N do
begin
SXY:=SXY+x[j]*y[j];
SX:=SX+x[j];
SY:=SY+y[j];
SX2:=SX2+x[j]*x[j];
end;
A:=((SX2-(SX)*SY))/N;
A:=A/(SX2-(SX*SX)/N);
ratay:=SY/N;
ratax:=SX/N;
B:=ratay-A*rataX;
writeln('N= ',N);
writeln('Jumlah x= ',SX:0:2);
writeln('Jumlah y= ',SY:0:2);
writeln('Jumlah x dikali y =',SXY:0:2);
writeln('Jumlah x kwadrat=',SX2:0:2);
writeln('Rata-rata x=',ratax:0:2);
 writeln('Rata-rata y=',ratay:0:2);
writeln('Y= ', A:0:2,'X- ', B:0:2);
end;
begin
regressi;
end.

Leave a Reply