MATLAB: How to get an equation of a line/curve from a data set(Matrix) with two variables

equationquadratic

Good morning Matlab community, I have a matrix A(171000,2) and I plotted the data as shown in the attached figure. I do need to derive the equation of the curve/line and I am pretty sure it is not linear, more like quadratic. Is there a function that can useful in matlab to determine the equation of the line? I would greatly appreciate any feedback, Thank you in advance Matlab! Amine

Best Answer

This is a not uncommon question. You have some curve, and you want to find the function that represents it. Here you have a huge amount of data, but even so, there will be no simple equation that you can write down.
It is clearly NOT linear. Nor is it arguably even remotely quadratic, nor will there be any simple "equation" that describes this curve. This curve simply does not have some simply polynomial form, and given the amount of data, it is sufficiently smooth that any polynomial will show significant lack of fit. But it does not have a polynomial shape, and you will not be remotely happy with a low order polynomial model. A sufficiently high order polynomial model will have obscene numerical problems.
So it very much depends on what you want to do with the result.
If all you want to do is use it to interpolate the function, then I would just use a spline.
If you need to also do some amount of smoothing (I see some possible junk near the bottom) then use a least squares spline, or some sort of regularized/smoothing spline. I'd suggest my SLM toolbox as a good choice. You won't get any function that you can write down from it though. You can evaluate it, differentiate it, plot it, etc.
If you really, desperately want some function that you can write down that looks like that curve, with some amount of effort you could find a nonlinear model that will approximate it. But the coefficients would mean nothing. The functional form would have no physical meaning. So why exactly would you do this? Ya got me guessing.
In the end, when you have no intelligently motivated physical model for what generated your data, and you have no model that makes some sense, even though it may not be clearly motivated from physical principles, my recommendation is often to just use a spline model. In fact, splines are one form of what I call a metaphorical model. A spline is a mathematical model of a thin, flexible beam. If you choose to use that same underlying mathematics for your data, as can often be done with many relations, then a spline is a good choice.