# comp.graphics.algorithms

## Subject: Re: How to fill unknown middle value in surface array

James,

you may use a Gauss Least Squares approach.
The formulas should be read by Courier New.

Given a 5x5 grid with 24 values z(x,y).
The center value has to be calculated
(approximated), using 24 neighbours.
Local coordinates x,y, centered in the middle.

Function (one possible choice):

F(x,y) = p0
+ p1*x + p2*y
+ p3*x^2 + p4*x*y + p5*y^2
+ p6*x^3 + p7*x^2*y + p8*x*y^2 + p9*y^3

Parameter column matrix,
(') means 'transposed':

P = (p0,p1,...,p9)'

Given values z(x,y):

Z = (z(-2,-2),...,(z(2,2))', 24 rows, without z(0,0)

Matrix 1:24,1:10 :

[1,x,y,x^2,x*y,y^2,x^3,x^2*y,x*y^2,y^3]
M = [..altogether k=1..24 rows ]
[1,x,...,y^3 ]

Fill matrices:
k=1
For y=-2 to +2 Do
For x=-2 to +2 Do
Begin
If Not (x=0 And y=0) Then
Begin
Fill row k of M, using x,y
Fill row element k of Z, using z(x,y)
k=k+1
End
End

M * P = Z

Least Squares by Gauss Normal equation:

M' * M * P = M' * Z

Solve 10 linear equations (Gauss or Cholesky).

Center value:

F(0,0) = p0

Best regards --Gernot Hoffmann