Problem with Power Regression

4 ビュー (過去 30 日間)
Skydriver
Skydriver 2019 年 7 月 19 日
コメント済み: the cyclist 2019 年 7 月 20 日
I have a coding to develop a formula using power regreesion
Here my coding:
plot(Xbin,Ybin,'+r'), hold on
p = polyfit(log(Xbin),log(Ybin),2);
m = p(1);
b = exp(p(2));
ezplot(@(x) b*Xbin.^m,[Xbin(1) Xbin(end)])
Error in Power_Regression (line 242)
ezplot(@(x) b*Xbin.^m,[Xbin(1) Xbin(end)])
I appreciate the help
Akhmad
  2 件のコメント
Image Analyst
Image Analyst 2019 年 7 月 19 日
Why not use fitnlm() for a better fit? I'm attaching several examples. Would you consider that (fitnlm) instead of taking the log and doing polyfit() on the logged data?
Skydriver
Skydriver 2019 年 7 月 20 日
Dear Cyclist,
I tried to follow your suggestion, but every coding ask about function table can you explain this?

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

採用された回答

the cyclist
the cyclist 2019 年 7 月 19 日
編集済み: the cyclist 2019 年 7 月 19 日
polyfit(...,2) is fitting a constant, linear, and quadratic term. Notice that the output vector p has three elements. You want this instead:
% Some made-up data
Xbin = (1:10)';
Ybin = 2 * Xbin.^3 + 0.07*randn(10,1);
figure
plot(Xbin,Ybin,'+r'), hold on
p = polyfit(log(Xbin),log(Ybin),1);
m = p(1);
b = exp(p(2));
ezplot(@(x) b*x.^m,[Xbin(1) Xbin(end)])
I also corrected the fact that you used @(Xbin) instead of @(x) in the function definition.
[Sorry if you saw some of the intermediate edits I did, before I realized the true source of your problem.]
  2 件のコメント
Skydriver
Skydriver 2019 年 7 月 20 日
Thank you, my coding is working know. I want to know how to write the euation and R square inside the figure?
Thank you
Akhmad
the cyclist
the cyclist 2019 年 7 月 20 日
Try the annotation command.
You could also use the text command, but annotation is more powerful, and handy to learn.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeModel Building and Assessment についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by