more useful options | |
PerlMonks |
Re: Surface fitting with PDLby pryrt (Abbot) |
on Aug 09, 2020 at 21:17 UTC ( [id://11120528]=note: print w/replies, xml ) | Need Help?? |
Xilman, Because you invoked "least squares fitting", I assume what you want is a planar least-squares fitting in 3d, analogous to the linear least-squares 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 column-vector of the coefficients a,b,c from the above equation, and B is the column-vector 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 best-fit, 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 Section
Seekers of Perl Wisdom
|
|