Perl: the Markov chain saw  
PerlMonks 
comment on 
( [id://3333]=superdoc: print w/replies, xml )  Need Help?? 
Xilman,
Because you invoked "least squares fitting", I assume what you want is a planar leastsquares fitting in 3d, analogous to the linear leastsquares in 2d, and that z is supposed be be linearly dependent on the others: ax+by+c = z You can see the algebra in this math.stackexchange answer, but basically you are solving A*X=B, where A is a matrix of the x and y data, X are the columnvector of the coefficients a,b,c from the above equation, and B is the columnvector of the z values for each x,y input. I haven't looked up the exact PDL syntax, but: An exact solution for 3 sets of (x,y,z) data would have PDL akin to $coeff_X = $matrix_A>inverse * $column_B;. But since you presumably have many points, not just three, since you invoked bestfit, you have to use the "left pseudo inverse", which would have a PDL implementation akin to $coeff_X = ($matrix_A>transpose * $matrix_A)>inverse * ($matrix_A>transpose) * $column_B;
update: I was close.
prints:
In reply to Re: Surface fitting with PDL
by pryrt

