Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

My problem is that I have a set of coordinates from a graph corresponding to a peak and need to find the vertex (highest value of the peak, with my data this may not correspond to a data-point). I wondered whether anyone knows how I could implement this in perl (or if anyone has done this before and has a neat method)?!

I am looking into implementing a quadratic function to solve this problem (possibly with the help of modules like Math::polynomial, but then you still have to do a lot of the math (and i dont know a nice way of doing algebra in perl). I would love to hear your ideas.

Replies are listed 'Best First'.
Re: Finding the vertex of a curve
by benn (Vicar) on May 23, 2003 at 11:34 UTC
    mathsy question: finding max of curve from discrete points seems to have a lot of answers to this - a couple of them including Math::Polynomial solutions. Could it be perchance that they / you / your professors are related? :)

    As for a 'nice' way of doing algebra in perl, it's pretty much the same as doing algebra in any other language - try taking some 'C' code and sticking a $ in front of everything :). This being a maths question, there's not really going to be a solution that doesn't involve maths somehow.

    If you come up with some code, feel free to post it here and I'm sure you'll get a lot of useful suggestions...but do have a go first. Hack something up - anything that looks like you've spent some brainpower yourself on the question.

    Cheers, Ben.

Re: Finding the vertex of a curve (slightly-Perl answer)
by svsingh (Priest) on May 23, 2003 at 15:31 UTC
    There are two situations that I can think of here...
    • The curve is defined by an equation: In this case you can use some calculus to find the derivative of the equation. I did some checking on CPAN and think Math::Polynomial::Solve may work for you. I haven't used it though.
    • The curve is a line-graph created by data points: I think this is more likely to be your situation, but don't understand how your peak could not be a data-point in this case since every segment on the graph starts and ends with datapoints.

    Please let us know what kind of data you're working with. You've got me curious now and shaking some of the rust off my math skills couldn't hurt either.