in reply to mathsy question: finding max of curve from discrete points

From what I remember of linear algebra, a quadratic solution can be found as follows (sorry, this is going to be poorly formatted; I don't know how to combine super/subscripts and pre tags):

Given (x1,y1), (x2,y2)...(xn, yn) are your data points, a least squares solution can be found by creating a matrix A as such:
x12 x1 1
x22 x2 1
...
xnn xn 1

and a vector b as such:
y1
y2
...
yn
We then want to solve for a vector x = (A, B, C) such that:
ATAx = ATb.
(Where AT is the matrix transpose of A). The A, B, and C that you find by solving that equation will be the coefficients in the quadratic polynomial y = Ax2 + Bx + C. If you know how to do matrix arithmetic, you should be able to swing it. I think that there are also modules on the CPAN that could help you with that.

thor

  • Comment on Re: mathsy question: finding max of curve from discrete points