Mã:
Clear[X, Y, n, temp, i, f, P];
n = Input["Nhap so n+1 diem"];
X = {};
i = 1;
While[i ≤ n, temp = Random[Integer, {-100, 100}];
    If[Intersection[X, {temp}] == {}, X = Append[X, temp];
      i++;];];
Y = Table[Random[Integer, {-100, 100}], {i, n}];
P = Table[
    Product[If[j ≠ i, (x - X[[j]])/(X[[i]] - X[[j]]), 1], {j, n}], {i, n}];
f = Simplify[Sum[Y[[i]] P[[i]], {i, n}]];
Print["P(x) = ", f];
Print["Do thi ham so"];
Plot[f, {x, -100, 100}];