RosettaCodeData/Task/Polynomial-regression/Ada/polynomial-regression-1.ada

13 lines
363 B
Ada
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays;
function Fit (X, Y : Real_Vector; N : Positive) return Real_Vector is
A : Real_Matrix (0..N, X'Range); -- The plane
begin
for I in A'Range (2) loop
for J in A'Range (1) loop
A (J, I) := X (I)**J;
end loop;
end loop;
return Solve (A * Transpose (A), A * Y);
end Fit;