There is a procedure that, based on 17 points (x from -3 to 1 with a step of 0.25), calculates the intermediate value of the function using the quadratic interpolation method. To calculate the coefficients, I use the Cramer method. Based on the results obtained, you need to build a graph. But as a result, the schedule is absolutely not consistent with expectations. Another procedure that derives the value of the function based on the argument entered by the user works normally and the results correlate with those obtained by the linear interpolation method. Thus, I suppose that the problem is in the schedule. Please help me find a bug.

Function code:

procedure TForm1.Button2Click(Sender: TObject); var mat,mata,matb,matc:array[0..2,0..2] of double; i,k:integer; xnow,ynow,a,b,deter,detera,deterb,deterc,anow,bnow,cnow,j:double; begin for i := 1 to 15 do begin for k := 0 to 2 do begin mat[k,0]:=xar[i+k-1]*xar[i+k-1]; mat[k,1]:=xar[i+k-1]; mat[k,2]:=1; end; deter:=(mat[0,0]*mat[1,1]*mat[2,2])+(mat[0,1]*mat[1,2]*mat[2,0])+(mat[1,0]*mat[2,1]*mat[0,2]) -(mat[2,0]*mat[1,1]*mat[0,2])-(mat[0,0]*mat[1,2]*mat[2,1])-(mat[1,0]*mat[0,1]*mat[2,2]); for k := 0 to 2 do begin mata[k,0]:=yar[i+k-1]; mata[k,1]:=xar[i+k-1]; mata[k,2]:=1; end; detera:=(mata[0,0]*mata[1,1]*mata[2,2])+(mata[0,1]*mata[1,2]*mata[2,0])+(mata[1,0]*mata[2,1]*mata[0,2]) -(mata[2,0]*mata[1,1]*mata[0,2])-(mata[0,0]*mata[1,2]*mata[2,1])-(mata[1,0]*mata[0,1]*mata[2,2]); for k := 0 to 2 do begin matb[k,0]:=xar[i+k-1]*xar[i+k-1]; matb[k,1]:=yar[i+k-1]; matb[k,2]:=1; end; deterb:=(matb[0,0]*matb[1,1]*matb[2,2])+(matb[0,1]*matb[1,2]*matb[2,0])+(matb[1,0]*matb[2,1]*matb[0,2]) -(matb[2,0]*matb[1,1]*matb[0,2])-(matb[0,0]*matb[1,2]*matb[2,1])-(matb[1,0]*matb[0,1]*matb[2,2]);; for k := 0 to 2 do begin matc[k,0]:=xar[i+k-1]*xar[i+k-1]; matc[k,1]:=xar[i+k-1]; matc[k,2]:=yar[i+k-1]; end; deterc:=(matc[0,0]*matc[1,1]*matc[2,2])+(matc[0,1]*matc[1,2]*matc[2,0])+(matc[1,0]*matc[2,1]*matc[0,2]) -(matc[2,0]*matc[1,1]*matc[0,2])-(matc[0,0]*matc[1,2]*matc[2,1])-(matc[1,0]*matc[0,1]*matc[2,2]); anow:=detera/deter; bnow:=deterb/deter; cnow:=deterc/deter; if i<15 then begin j:=0.025; xnow:=xar[i]; while xnow<xar[i+1] do begin ynow:=a*xnow*xnow+b*xnow+cnow; Series1.AddXY(xnow,ynow, '', clBlack); xnow:=xar[i] + j; j:=j+0.025; end; end else begin j:=0.025; xnow:=xar[i-1]; while xnow<xar[i+1] do begin xnow:=xar[i-1] + j; ynow:=a*xnow*xnow+b*xnow+cnow; Series1.AddXY(xnow,ynow, '', clBlack); j:=j+0.025; end; end; end; end; 

    1 answer 1

    In general, I found a mistake. In line

      ynow:=a*xnow*xnow+b*xnow+cnow; 

    must be

     ynow:=anow*xnow*xnow+bnow*xnow+cnow; 

    It is unlikely that someone is interested, but found it necessary to unsubscribe.