program LagNew; uses crt; Const MaxPont=10; var x : array [0..MaxPont] of real; y : array [0..MaxPont] of real; hely : real; n : integer; i : integer; c : char; procedure Pontok_bekerese; var j:integer; hiba:boolean; begin clrscr; repeat write('Pontok sz ma (0-',MaxPont,'):'); readln(n); until (n>=1) and (n<=MaxPont); for i:=0 to n-1 do begin repeat hiba:=false; write('x[',i,']:='); readln(x[i]); for j:=0 to i-1 do if x[j]=x[i] then hiba:=true; until not(hiba); write('y[',i,']:='); readln(y[i]); end; end; function Newton : real; var c,new,p,s : real; i,j,k : integer; begin p:=0; for i:=0 to n-1 do begin if i=0 then begin new:=1; c:=y[0]; end else begin new:=1; for j:=0 to i-1 do new:=new*(hely-x[j]); c:=0; for j:=0 to i do begin s:=1; for k:=0 to j-1 do s:=s*(x[j]-x[k]); for k:=j+1 to i do s:=s*(x[j]-x[k]); c:=c+y[j]/s; end; end; p:=p+c*new; end; Newton:=p; end; function Lagrange : real; var p,L : real; i,j : integer; begin p:=0; for i:=0 to n-1 do begin L:=1; for j:=0 to i-1 do L:=L*((hely-x[j])/(x[i]-x[j])); for j:=i+1 to n-1 do L:=L*((hely-x[j])/(x[i]-x[j])); p:=p+y[i]*L; end; Lagrange:=p; end; begin Pontok_bekerese; c:='i'; repeat writeln; write('x:=');readln(hely); writeln('Lagrange -- p(x)=',Lagrange:2:2); writeln('Newton -- p(x)=',Newton:2:2); writeln; write('Akarsz £jabb pontot (i/n) ?'); readln(c); until (c='n') or (c='N'); end.