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

3 ビュー (過去 30 日間)
Joel Sande
Joel Sande 2015 年 8 月 7 日
コメント済み: Joel Sande 2016 年 4 月 18 日
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
Azzi Abdelmalek 2015 年 8 月 7 日
編集済み: Azzi Abdelmalek 2015 年 8 月 7 日
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)

その他の回答 (2 件)

Brendan Hamm
Brendan Hamm 2015 年 8 月 7 日
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*');
  5 件のコメント
Joel Sande
Joel Sande 2015 年 8 月 11 日
Thanks for the advice.
Joel Sande
Joel Sande 2016 年 4 月 18 日
Yes, Finally I used Polyfit

サインインしてコメントする。


Walter Roberson
Walter Roberson 2015 年 8 月 7 日
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".
  2 件のコメント
Joel Sande
Joel Sande 2015 年 8 月 11 日
Thanks !
Joel Sande
Joel Sande 2016 年 4 月 18 日
It is exactelly what I used, because I didn t know the order of the polynom.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by