Effacer les filtres
Effacer les filtres

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

39 vues (au cours des 30 derniers jours)
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

Réponse acceptée

John D'Errico
John D'Errico le 15 Déc 2016
Modifié(e) : John D'Errico le 15 Déc 2016
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.
  1 commentaire
Amine Ben Ayara
Amine Ben Ayara le 15 Déc 2016
Hello John, First, let me thank you for taking the time to explain in such an elaborate way! I really appreciate it. Lets get something clear, I am desperate for a solution at this point! :) So I updated the figure and now, perhaps it is more explanatory. The objective to determine the area under the horizontal line for each curve so I can compute the change in the total area between the 1st and 2nd curve (In micro-economics terms: change in net social welfare) Each curve represents a supply curve (Marginal cost curve) for carbon sequestration, and the flat line is the price or marginal benefit from adding one more unit for carbon storage (equivalently, removing one unit of CO2 from the atmosphere). By computing the areas under the MB-flat line and between each MC curve I can then put a monetary value on the change in the social welfare! I wanted to explain because you seemed interested! and thank you again! Amine

Connectez-vous pour commenter.

Plus de réponses (1)

KSSV
KSSV le 15 Déc 2016
doc polyfit.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by