VandermondeMatrix[nodes_]:=(
list=nodes;
vanmat=Table[Table[If[list[[j]]==0 &&i==0,1,(list[[j]])^i],{i,0,Length[nodes]-1}],{j,1,Length[nodes]}];
Return[vanmat];
);
LagrangePolynomial[nodes_,values_,x_]:=(
helpmatrix=VandermondeMatrix[nodes];
answermatrix=LinearSolve[helpmatrix,values];
If[answermatrix[[1]]≠0,sum=answermatrix[[1]],0];
For[i=2,i≤Length[nodes],i++,
If[answermatrix[[i]]≠0,sum=sum+answermatrix[[i]]*x^(i-1)]
];
sum
);
testdata1={0,1,2};
testdata2={1,2,5};
LagrangePolynomial[testdata1,testdata2,x]

data1={1920,1930,1940,1950,1960,1970,1980,1990};
data2={106460000,123080000,132120000,152270000,180670000,205050000,227230000,249460000};
mergelists[l1_,l2_]:=(
length=If[Length[l1]≤Length[l2],Length[l1],Length[l2]];
Table[{l1[[k]],l2[[k]]},{k,1,length}]
);
data3=mergelists[data1,data2]

plot1 = ListPlot[data3,PlotStyle-> Blue,AxesLabel->{"Година","Население"},PlotLegends->{"Данни"}]

LagrangePolynomial[data1,data2,x]

plot2=Plot[LagrangePolynomial[data1,data2,x],{x,1920,1990},PlotStyle->Red,AxesLabel->{"Година","Население"},PlotLegends->{"Полином на Лагранж"}]

allplot=Show[plot1,plot2]