SmartFactory_NEOL/SOURCE/Agent,Kiosk/NEOL_GTWYAgent_D104_PG/Calibration.pas
2026-09-04 14:08:41 +09:00

47 lines
994 B
ObjectPascal

unit Calibration;
interface
uses
System.SysUtils;
type
TCalibration = class
private
a, b: Double; // 보정식의 기울기와 절편
public
constructor Create(xValues, yValues: TArray<Double>);
function Calibrate(x: Double): Double;
end;
implementation
{ TCalibration }
function TCalibration.Calibrate(x: Double): Double;
begin
Result := a * x + b; // 보정된 값 계산
end;
constructor TCalibration.Create(xValues, yValues: TArray<Double>);
var
i, N: Integer;
sumX, sumY, sumXY, sumX2: Double;
begin
N := Length(xValues);
if N <> Length(yValues) then raise Exception.Create('Input arrays must have the same length.');
sumX := 0;
sumY := 0;
sumXY := 0;
sumX2 := 0;
for i := 0 to N - 1 do begin
sumX := sumX + xValues[i];
sumY := sumY + yValues[i];
sumXY := sumXY + xValues[i] * yValues[i];
sumX2 := sumX2 + xValues[i] * xValues[i];
end;
a := (N * sumXY - sumX * sumY) / (N * sumX2 - sumX * sumX);
b := (sumY - a * sumX) / N;
end;
end.