How to find the equation of a graph after getting Xdata and Ydata ?

1 view (last 30 days)
Joel Sande on 7 Aug 2015
Commented: Joel Sande on 18 Apr 2016
x = [0 1 2 3 4 5 6 7 8 9 10];
y = [4 3 4 7 12 19 28 39 52 67 84];
% How to find the function y = F(x) ??
% because I need for example to know
% if x = 1.5
% y = ??
% the solution should be something regarding regression.

Azzi Abdelmalek on 7 Aug 2015
Edited: Azzi Abdelmalek on 7 Aug 2015
You can find yi by interpolation
x = [0 1 2 3 4 5 6 7 8 9 10];
y = [4 3 4 7 12 19 28 39 52 67 84];
xi= 1.5
yi=interp1(x,y,xi)
Joel Sande on 7 Aug 2015
GREAT !! perfect

Brendan Hamm on 7 Aug 2015
The easiest way would be to use the polynomial fitting functions. For this you need to know what order polynomial to fit, so visualize the data:
plot(x,y)
The data you gave looks quadratic, so let's find the coefficients for a second order polynomial:
coeff = polyfit(x,y,2);
Now evaluate the polynomial at a new value of x:
xNew = 1.5;
yNew = polyval(coeff,xNew);
plot(xNew,yNew,'r*');
Joel Sande on 11 Aug 2015
Joel Sande on 18 Apr 2016
Yes, Finally I used Polyfit

Walter Roberson on 7 Aug 2015
one of the infinite number of solutions is:
x = [0 1 2 3 4 5 6 7 8 9 10];
y = [4 3 4 7 12 19 28 39 52 67 84];
pp = polyfit(x, y, length(x)-1);
y1_5 = polyval(pp, 1.5)
Another of the infinite solutions is:
x = [0 1 2 3 4 5 6 7 8 9 10];
y = [4 3 4 7 12 19 28 39 52 67 84];
y1_5 = 19;
It is not mathematically possible to distinguish between these two solutions as to which one is "more correct".
Joel Sande on 11 Aug 2015
Thanks !
Joel Sande on 18 Apr 2016
It is exactelly what I used, because I didn t know the order of the polynom.