I want to make curve fitting to these points but when i made it the blue straight line appeared. What does it mean ?

2 件のコメント

Umar
Umar 2024 年 7 月 29 日
Hi @noura,
If you don’t mind, can you share your code with us to help resolve your issue.
dpb
dpb 2024 年 7 月 29 日
You don't need his code; the answer is obvious by inspection. Put any set of symmetric points in and overall OLS will always return the mean; it's inevitable conclusion from the basis of the method to minimize the overall error sum of squares.

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

 採用された回答

dpb
dpb 2024 年 7 月 29 日
編集済み: dpb 2024 年 7 月 29 日

0 投票

The top and bottom are identical pairs above and below the mean; hence when/if you fit the whole dataset, the single line that best fits all the data is (drum roll, please...) the mean.
You need two fits; one for the upper and one for the lower. The slope of one will be exactly the negative of the other, but the two intercepts will be different.
X=[16 17.5 20 25 32.5 37 42.5 45 48].';
Y=[0 9 17 21 27 34 41 48 55 ];
DY=Y-Y(end);
Y=[Y;Y(end)-DY].';
scatter(X,Y,'filled')
box on, grid on
ylim([-5 118])
b1=polyfit(X,Y(:,1),3)
b1 = 1x4
0.0037 -0.3546 11.9781 -113.5101
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
b2=polyfit(X,Y(:,2),3)
b2 = 1x4
-0.0037 0.3546 -11.9781 223.5101
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y1=polyval(b1,X);
y2=polyval(b2,X);
hold on
plot(X,y1,'b-')
plot(X,y2,'r-')

7 件のコメント

noura
noura 2024 年 7 月 29 日
Not possible that one polynomial define the all points ?
Umar
Umar 2024 年 7 月 29 日
@noura,
Could you share code snippet or example to share with us by explaining what exactly you are looking to achieve by mentioning, “ I want to make curve fitting to these points” since I can’t archive points from attached png file. Hope it makes sense.
dpb
dpb 2024 年 7 月 29 日
"...one polynomial define the all points ?"
You can observe it is double-valued function -- at each X, there are two possible y values. So, no there is no single polynomial that can define both of them.
How would you propose being able to tell which value of Y, the upper or lower, is supposed to be returned given a value of X?
The issue is as outlined before, when you combine the two Y at each X, you get a constant which gives you the flat line you had before. As you can see by inspection, the coefficients of the two are the negative of each other for the terms in X while the intercepts are different.
dpb
dpb 2024 年 7 月 29 日
@Umar, the data I created matches the example closely enough although the actual data are totally immaterial -- any set that is symmetric about the overall mean will suffice to create the same scenario.
noura
noura 2024 年 7 月 29 日
Yes i understood thank you
Umar
Umar 2024 年 7 月 29 日
@dpb, thanks for your contribution and sharing your thoughts, really appreciated. @noura, please go ahead accept @dpb answer and give him a vote. If there are still further questions or issues, please let us know, we will be more happy to help.
dpb
dpb 2024 年 7 月 30 日
編集済み: dpb 2024 年 7 月 30 日
"...the coefficients of the two are the negative of each other for the terms in X while the intercepts are different."
Also, notice that
X=[16 17.5 20 25 32.5 37 42.5 45 48].';
Y=[0 9 17 21 27 34 41 48 55 ];
DY=Y-Y(end);
Y=[Y;Y(end)-DY].';
b1=polyfit(X,Y(:,1),3);
b2=polyfit(X,Y(:,2),3);
mean_intercept=mean([b1(end) b2(end)])
mean_intercept = 55.0000
mean_y=mean(Y,'all')
mean_y = 55
The average of the two intercepts is the mean of the overall data to within machine precision/roundoff in the fitting calculations...
That being so, it is in one sense only one polynomial, the second is completely known by only fitting the first; the issue still being there isn't any convenient way to return the double-valued function from only a f(x).

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

質問済み:

2024 年 7 月 29 日

編集済み:

dpb
2024 年 7 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by