Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|cite|improve this question
Do you really need a function or would a look-up be sufficient? – NoChance Mar 14 '12 at 10:37
@EmmadKareem: I quote myself "calculation time quite matters and therefore I can't implement it as a lookup table" ;) – powerbar Mar 14 '12 at 10:39
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. – NoChance Mar 14 '12 at 10:42
@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. – powerbar Mar 14 '12 at 10:44
I see now, this is a valid scenario of course. – NoChance Mar 14 '12 at 10:47

The keyword is Curve Fitting. You are trying to fit a known curve that is close to the data points that you have. ( You are posting the question probably not in the right group.

Check 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".

share|cite|improve this answer
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. – NoChance Mar 14 '12 at 12:49
@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 ;) – powerbar Mar 14 '12 at 15:47
@KirthiRaman, the link is good. Thanks. – NoChance Mar 14 '12 at 16:32

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

share|cite|improve this answer
I thought about splitting the data into intervalls, too. Could be worth a try. – powerbar Mar 14 '12 at 15:49

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$.

share|cite|improve this answer
I will give this a try, could be a good idea to transform the data to better match regression. – powerbar Mar 14 '12 at 15:48
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 :( – powerbar Mar 14 '12 at 16:09
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}$. – Julián Aguirre Mar 14 '12 at 21:33
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. – powerbar Mar 15 '12 at 7:58

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}$.

share|cite|improve this answer
up vote 1 down vote accepted

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.

share|cite|improve this answer
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? – powerbar Mar 16 '12 at 10:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.