How to find equation of curve if just graph is given

Hello All,
I have just graph with me in matlab and from that I have to find equation of curve. Can anybody help me to find that ?

Answers (1)

You will have to make some assumptions about the functional form of the curve... for example if you know the curve is of the form y = b1 + b2*x + b3*x^2 + ...., you can solve for b by b = ((X'X)^-1)*X'*Y where X = [1 x x^2 ...].
Conrad

5 Comments

Here is an example:
% Create dummy data.
f = inline('3 + 2*x + 4*x.^2');
x = (0:0.1:2)';
y = f(x);
% Recover coefficients.
X = [ones(numel(x),1) x x.^2];
b = (inv(X'*X))*X'*y;
You will see that the b coefficients corresponds exactly to the coefficients of the original polynomial function.
In general, if you chosen functional form is not the true functional form of the data, the solution will give the "closest" curve in the least squares sense. You could also try more exotic approaches....piece wise fitting etc.
Pranav
Pranav on 27 Jul 2012
Edited: Pranav on 27 Jul 2012
Conrad thanks for reply. How to know that the equation pattern I mean polynomial, exponential etc. I just have a curve. Please help me.
Sorry no easy answer here. How is the data generated or what is the underlying model? Without having an underlying model/functional form there are an infinite number of possibilities... you will have to make an assumption.
If you really have no idea, you could assume various basic forms and see which one fits the data the best in a least squares sense.
NO, NO, NO!!!!!!!! Don't teach people to use the normal equations, i.e., b = ((X'X)^-1)*X'*Y. Terrible numerically. Just silly when a better solution exists. You are squaring the condition number of the problem, so this is bad when the system is at all ill-conditioned. Then you are using inv on a problem where it is less than desirable.
b = X\Y;
Don't continue to propagate the bad things you learned.
John, rather than just criticising I would prefer, as I am sure Pranav would as well, that you present your better solution.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 27 Jul 2012

Community Treasure Hunt

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

Start Hunting!