#### Archived

This topic is now archived and is closed to further replies.

# writing a least-squares approximation for a f(x,y) = z type equation- good sources ?

This topic is 5277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

...yea... I''ve got this passel of data that is of the form f(x,y) = z, and need to write an approximation function. It needs to give me the coefficients and error for a polynomial surface, assuming the data itself is a little erroneus. I''m pretty sure a planar approximation would be incorrect. I''ve been googling, but nothing seems to come up in the line of what I''m looking for, mostly single-valued functions. Any good sites that would describe algorithm related to this kind of function? Thanks, -paul

##### Share on other sites
Sounds like you are interested in bilinear regression or some other more advanced multivariate data analysis algorithms. I''d just google for bilinear regression and go from there.

##### Share on other sites
start with a plot of the function, to see how complex it is
how many values do you have?

here we go...
lets use a bivariat polynom of degree 2. yep its more than a plane.

f(x,y) = a_22(x^2*y^2) + a_21(x^2*y)... (1)
or sum_i=0_2(sum_j=0_2 (of a_ij*x^i*y^j)) (2)..ok hard to read

you can write it more cleaner in matrix notation: M*a = z.
Where ''a'' is the vector of nine a_ij. Each equation of your dataset gives a row of ''M''.
If the data would perfectly fit the function you can write
Ma-z=0, or if not there will be some error e=Ma-z.
You wanted least square? I dont know the derivation... but i afaik the solution for Ma=z ist least square.

simple...ey?
regards, tobes

##### Share on other sites
quote:
Original post by Vlion
I''ve got this passel of data that is of the form f(x,y) = z, and need to write an approximation function.

It needs to give me the coefficients and error for a polynomial surface, assuming the data itself is a little erroneus.

Sounds like homework to me. Otherwise it would would probably say "I WANT to write an approximation function" etc...
Unless you''d kindly like to put me in my place.

That aside, it''s probably above a large proportion of the posters here to be able to help with this anyway.

##### Share on other sites
Do a google for Numerical Recipies in C it likely contains exactly what you''re after, it''s a book full of good stuff related to scientific computing. It should still be freely available as a PDF or PS if you don''t actually want the book.

##### Share on other sites
Suppose the function you wish to fit is of the form a*x + b*y + c. You wish to solve the system of linear equations a*x1 + b*y1 + c = z1, a*x2 + b*y2 + c = z2, ..., a*xn + b*yn + c = zn. Write this in matrix form as Ax = z, where A is an n by 3 matrix containing the x and y coordinates in the first two columns and all 1''s in the third column, x is a 3 by 1 matrix containing the unknowns a, b, c, and z is an n by 1 matrix containing the z coordinates. In most cases, this system of linear equations will be inconsistent and have no exact solution because there are more equations (n) than unknowns (3). To make this system consistent, multiply both sides of the equation Ax = z by the transpose of A (AT, a 3 by n matrix) to get ATAx = ATz. You can show by various theorems from linear algebra that this system is consistent. If ATA is invertible, then the solution is x = (ATA)-1ATz. Otherwise, you have to use Gauss-Jordan elimination to solve the system.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 12
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633314
• Total Posts
3011325
• ### Who's Online (See full list)

There are no registered users currently online

×