2
$\begingroup$

Chart Example

I would like to be able to do something like this in c++.

How can I go about creating a nice curved line like this through a list of points?

Can anyone please point me in the direction of the relevant maths?

Edit 1:

Here is another example of what I would like from the output.

Graph 2

I need to be able to calculate Y for any given X...

Edit 2:

Please don't just post existing APIs, chances are they will be useless on an MCU. I would prefer reading the maths...

  • 0
    What's an API? What's an MCU?2012-09-12

2 Answers 2

2

I wrote up some notes on cubic splines, just a couple of pages about a third of the way through these notes. I think the calculations are not too hard.

  • 0
    Yes, you're right (although the example you gave in the original question has equally spaced points). The calculations are more difficult when the points are not equally spaced, and I'm afraid I have nothing written up - but my guess is that if you keep looking you'll find it written up somewhere, and the formulas won't be all that bad for computing.2012-09-12
0

One way is to consider the method of Quadratic Least Square Regression. For an example in C# see CodeProject-Least Square Regression for Quadratic Curve.

The point to notice is that such methods make assumptions about the function value for the data you don't provide. For example, it assumes that data at $x=4.5$. Such assumptions may not be correct.

I assume that Excel is using QR Decomposition method to produce your chart.

For starters, this introduction may help: Seminar-Curve Fitting

  • 0
    Well, if you had small number of points, say N, one could use a specific polynomial of degree <= N (where N is how many data points you have). Such an algorithm may call for solving N simultaneous equations, but as per your case, I don't think that this would work for you.2012-09-12