1
$\begingroup$

first I have to apologize for any uncorrect naming or categorisation of my question, as I am an electrical engineer rather than a mathematican.

I try to find a simple solution for my problem:

I have a given number of data points (x,y) that "look like" they could be approximated by an easy function. As this will be used in a simulation many times, calculation time quite matters and therefore I can't implement it as a lookup table. Also, some error isn't a problem at all.

There are some online tools, that do what I want:

Nevertheless, my data looks pretty much like -sqrt(x). So do you now any tools that includes regressions by (square?) roots? Because a sqrt() function isn't approximated very well by polynomial equations for values near the x axis.

Thank you very much!

Edit: It rather looks like sqrt(-x), I added an image.

graph

  • 0
    Do you really need a function or would a look-up be sufficient?2012-03-14
  • 0
    @EmmadKareem: I quote myself "calculation time quite matters and therefore I can't implement it as a lookup table" ;)2012-03-14
  • 0
    I believe lookups, in cases, may be faster than functions (either lockups based on hashing or binary search). In languages like C# a Dictionary data structure is extremely fast and could allocate millions of entries.2012-03-14
  • 0
    @EmmadKareem: Let's assume we are on a mobile device without standard libraries, nor enough space. Also, I would have to implement interpolation between the data points.2012-03-14
  • 0
    I see now, this is a valid scenario of course.2012-03-14

5 Answers 5

1

For the record, an answer not yet posted:

Use the CurveFitting Toolbox of Matlab. It has way more regressions build in than the online tools mentioned above. I get pretty good results by playing around with the regression functions for each curve.

  • 0
    I just implemented the functions and used Matlab CurveFitting Toolbox to calculate the coefficients for a 4-grade polynomial function. I hope accept my own answer isn't supposed to be rude or something?2012-03-16
3

The keyword is Curve Fitting. You are trying to fit a known curve that is close to the data points that you have. (http://en.wikipedia.org/wiki/Curve_fitting). You are posting the question probably not in the right group.

Check https://stackoverflow.com/questions/878200/java-curve-fitting-library if you find answers. If you don't find it yet you will find in the programming language choice of yours by doing just a web search with keyword "Curve Fitting".

  • 0
    I think the OP is not looking for drawing or plotting the points. He is looking for an equation where given an x value, the equation produces a y-value.2012-03-14
  • 0
    Check http://www.ce.ufl.edu/~kgurl/Classes/Lect3421/NM5_curve_s02.pdf2012-03-14
  • 0
    @KirthiRaman: Thank you for giving me the correct term, I will search for curve fitting. But actually I am not searching for a library for curve fitting, but rather for a tool, that does this for me (I will need this only once). I could write my own tool, but this looks like a lot of overhead to me ;)2012-03-14
  • 0
    @KirthiRaman, the link is good. Thanks.2012-03-14
2

I am sure there are better ways to do this, but this is the only one I know. Since you accept some error in the y-values, Looking at your original curve, I noticed that you could approximate the values by using 3 lines and an ellipse.

for x between 0 and 500 use: $y= -0.05x+50$

for x between 501 and 640 use: $y=-0.07x+61.04$

for x between 641 and 700 use: $y=-0.1x+80.19$

for x between 701 and 720, use $y=0.25\sqrt{400-(700-x)^2}$

enter image description here

  • 0
    I thought about splitting the data into intervalls, too. Could be worth a try.2012-03-14
1

Do a linear regression on the $\log$ of the data. If $\log y\approx a\log x+b$, then $y\approx b\,x^a$. If $\sqrt{\quad}$ fits the data, you should get $a\approx .5$.

  • 0
    I will give this a try, could be a good idea to transform the data to better match regression.2012-03-14
  • 0
    I tried to find a curve for (x,log y) instead of (x,y). The errors is quite the same, I guess my data isn't a real root, but looks like one :(2012-03-14
  • 0
    Try a curve for $(\log x,\log y)$. A curve for $(x,\log y)$ is appropriate if you suspect an exponential law like $y=a\,e^{bx}$.2012-03-14
  • 0
    Problem is, I don't have a clue what function is behind the data points. (To be more precise, which functions, because the data is defined section by section. I tried '(log x, log y)' but the error is quite the same.2012-03-15
1

You can test your guess that there is a square root behind the data by plotting $x$ against the square of $y$; if your guess is correct than that would be a straight line. That also gives you a tool to do regression: assuming you know how to do linear regression (how to find a line $y=ax+b$ through data points), you can do linear regression to the data points $(x,y^2)$ and get a relation of the form $y^2 = ax+b$ or $y = \sqrt{ax+b}$.