How to find the equation of a graph after getting Xdata and Ydata ?
이전 댓글 표시
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.
채택된 답변
추가 답변 (2개)
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
Brendan Hamm
2015년 8월 7일
For more complex linear models you can take a look at fitlm in the Statistics and Machine Learning Toolbox.
Joel Sande
2015년 8월 7일
Brendan Hamm
2015년 8월 10일
If you want to assume the data you had was from a one dimensional polynomial, then this works fine (as interp1 is doing a 1 dimensional linear interpolation). On the other hand if you want the requirement that, "the solution should be something regarding regression", then polyfit or fitlm would be the appropriate choice.
Joel Sande
2015년 8월 11일
Joel Sande
2016년 4월 18일
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".
카테고리
도움말 센터 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!