program LagrangeInterpolation;
const
MaxExperts = 5;
MaxQuestions = 3;
type
TDataArray = array[1..MaxExperts, 1..MaxQuestions] of Real;
var
Data: TDataArray;
NumExperts, NumQuestions: Integer;
// Функция для интерполяции методом Лагранжа
function LagrangeInterpolate(const X, Y: array of Real; N: Integer; Xi: Real): Real;
var
i, j: Integer;
Term, Result: Real;
begin
Result := 0.0;
for i := 0 to N - 1 do
begin
Term := Y[i];
for j := 0 to N - 1 do
begin
if i <> j then
Term := Term * (Xi - X[j]) / (X[i] - X[j]);
end;
Result := Result + Term;
end;
LagrangeInterpolate := Result;
end;
// Основная программа
var
X, Y: array[1..MaxExperts] of Real;
i, j: Integer;
InterpolatedValue, Xi: Real;
begin
// Ввод данных экспертов вручную
NumExperts := 5;
NumQuestions := 3;
// Пример данных: строки — эксперты, столбцы — ответы на вопросы
Data[1, 1] := 5; Data[1, 2] := 7; Data[1, 3] := 6;
Data[2, 1] := 6; Data[2, 2] := 8; Data[2, 3] := 7;
Data[3, 1] := 5; Data[3, 2] := 6; Data[3, 3] := 7;
Data[4, 1] := 7; Data[4, 2] := 8; Data[4, 3] := 6;
Data[5, 1] := 6; Data[5, 2] := 7; Data[5, 3] := 8;
// Выполнение интерполяции для каждого вопроса
for j := 1 to NumQuestions do
begin
// Инициализируем данные для интерполяции
for i := 1 to NumExperts do
begin
X[i] := i; // Позиция эксперта
Y[i] := Data[i, j]; // Ответ эксперта на вопрос j
end;
// Вывод интерполированных значений для промежуточных точек
WriteLn('Интерполированные значения для вопроса ', j, ':');
Xi := 1.0;
while Xi <= NumExperts do
begin
InterpolatedValue := LagrangeInterpolate(X, Y, NumExperts, Xi);
WriteLn('Эксперт ', Xi:4:1, ': ', InterpolatedValue:8:2);
Xi := Xi + 0.1;
end;
end;
end.
cHJvZ3JhbSBMYWdyYW5nZUludGVycG9sYXRpb247Cgpjb25zdAogIE1heEV4cGVydHMgPSA1OwogIE1heFF1ZXN0aW9ucyA9IDM7Cgp0eXBlCiAgVERhdGFBcn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