-4

How should I solve my equations in Perl?

I know binary search is one solution (and perhaps pretty fast for my equations) but I would like to know if there is a ready to use solutions such as math packages or libraries so that I can use them instead of implementing my own solver?

NOTE:

  • This is, find x for a given y.
  • The functions are strictly increasing
  • The equations usually look like: y = a + b*sqrt(x) + b*x or y = sqrt(a*(x-b)**2*(x-c)/(x-d))
  • Please don't complain that "this is off topic" or "you should ask this in http://math.stackexchange.com". I want to see this problem from the programming point of view, particularly in Perl!
Ali Abbasinasab
  • 382
  • 3
  • 13
  • Any chance you could combine a function with `eval` and compute most such equations directly? Or when you say "solve" are you meaning in the mathematical sense, such as "find the zeroes of the quadratic `y=x^2+3x-7`"? – abiessu Jul 10 '14 at 16:48
  • Find `x` for a given `y`. Read the question carefully. – Ali Abbasinasab Jul 10 '14 at 16:52

2 Answers2

3

Have you considered using libraries? There's Math::LP, for instance.

See the Perl and Math tutorial from PerlMonks for more info.

dsm
  • 10,263
  • 1
  • 38
  • 72
2

Search for symbolic math on MetaCPAN. Lots of interesting looking options. https://metacpan.org/search?q=symbolic+math

Bill Ruppert
  • 8,956
  • 7
  • 27
  • 44