
16.12.2010, 11:34
|
Местный
|
|
Регистрация: 31.05.2010
Адрес: Москва
Сообщения: 466
Версия Delphi: 7
Репутация: 40
|
|
Вот так:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure Regress(num: integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure Tform1.Regress(num: integer); {num кол-во элементов}
var
a, b, x_avg, y_avg, temp, temp2, cor: real;
t, min, max: integer;
ch: char;
begin
y_avg := 0;
x_avg := 0;
for t := 1 to num do
begin
y_avg := y_avg + StrToFloat(StringGrid1.Cells[t,1]);
x_avg := x_avg + StrToFloat(StringGrid1.Cells[t,0]);
end;
x_avg := x_avg/num;
y_avg := y_avg/num;
temp := 0; temp2 := 0;
for t := 1 to num do
begin
temp := temp +(StrToFloat(StringGrid1.Cells[t,1]) - y_avg)*(StrToFloat(StringGrid1.Cells[t,0])-x_avg);
temp2 := temp2 +(t - x_avg)*(t-x_avg);
end;
b := temp/temp2;
a := y_avg-(b*x_avg);
Image1.Canvas.Brush.Color:=clWhite;
Image1.Canvas.Pen.Color:=clWhite;
Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
Image1.Canvas.Brush.Color:=clRed;
Image1.Canvas.Pen.Color:=clRed;
For t:=1 to num do
image1.Canvas.Ellipse(Trunc(StrToFloat(StringGrid1.Cells[t,0]))-2,Image1.Height -Trunc(StrToFloat(StringGrid1.Cells[t,1]))-2,
Trunc(StrToFloat(StringGrid1.Cells[t,0]))+2,Image1.Height -Trunc(StrToFloat(StringGrid1.Cells[t,1]))+2);
Image1.Canvas.Pen.Color:=clBlack;
image1.Canvas.MoveTo(1, Image1.Height - Trunc(a+b));
image1.Canvas.LineTo(100,Image1.Height - Trunc(a+b*100));
Label2.Caption:='Y = '+FloatToStr(Trunc(b*100)/100)+'x + '+FloatToStr(Trunc(a*100)/100);
end;
end.
Компоненты сами на форму накидаете!
киньте кнопку и 2 раза на нее нажмите:
появится ее (кнопки) обработчик туда впишите
чтоб было так:
Код:
procedure TForm1.Button1Click(Sender: TObject);
begin
Regress(12);
end;
__________________
Новый вирус - "БОМЖ"! Он просто роется в Корзине...и спит под ярлычком "Сетевое окружение"
|