From: Alex Fenton Date: 2007-12-17T11:40:17+09:00 Subject: Re: Curve fitting to data Phil Rhoades wrote: > On Sun, 2007-12-16 at 23:55 +0000, Thomas Adam wrote: >> On 16/12/2007, Phil Rhoades wrote: >>> People, >>> >>> Does anyone know of a Ruby app that will fit a curve to data eg fitting >>> a curve to: >>> >>> -10 0 >>> -9 19 >> This looks like a prime candidate for GNUPlot -- which ruby has bindings for. > > > I think GNUPlot requires the knowledge of the type of fn you are trying > to fit - I want the software to TELL me what sort of fn it is eg for the > data: You can access the "R" statistical package via Ruby, which seems to have curve fitting capabilities. But this would involve learning R, which I've found to have a steeper curve than I cared to climb. More generally, I think for most scientific purposes, it's a good idea to have an idea of the type of curve (power, quadratic, cubic etc) that might underlie the observed data. Most applications enforce this. If you know the general form of the equation that's being fitted ( eg ax^2 + bx + c for a quadratic), it would be possible to get estimates for a, b and c by using eg ordinary least squares to find a solution that minimises the difference between observed and predicted values. How you get to that with acceptable time is an algorithmic question... But nothing I know of exactly in Ruby. You might take a look at the source code for the website you linked to: http://pythonequations.cvs.sourceforge.net/pythonequations/PythonEquations/DESolver/DESolver.py?revision=1.2&view=markup Maybe a fun one for a Ruby Quiz sometime? alex