Fitting data into a required function

1 回表示 (過去 30 日間)
Vishal Dolas
Vishal Dolas 2021 年 2 月 13 日
コメント済み: Star Strider 2021 年 2 月 13 日
I am trying to fit this data -
x = [0.001 0.01 0.1 1 10];
y = [63.5 74.5 94.1 94.2 103.5];
into a function y = m*x^n
polyfit and lsqcurvefit not seem to be working here
can someone help me?

採用された回答

Star Strider
Star Strider 2021 年 2 月 13 日
Try this:
x = [0.001 0.01 0.1 1 10];
y = [63.5 74.5 94.1 94.2 103.5];
fcn = @(b,x) b(1).*x.^b(2);
B0 = rand(2,1);
B = lsqcurvefit(fcn, B0, x, y)
figure
plot(x, y, 'p')
hold on
plot(x, fcn(B,x), '-r')
hold off
set(gca, 'XScale','log') % Optional
grid
xlabel('X')
ylabel('Y')
legend('Data', sprintf('y = %.3f\\cdotx^{%.3f}', B), 'Location','E')
.
  2 件のコメント
Vishal Dolas
Vishal Dolas 2021 年 2 月 13 日
Thanks a lot it worked!!
Star Strider
Star Strider 2021 年 2 月 13 日
As always, my pleasure!

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

その他の回答 (1 件)

randerss simil
randerss simil 2021 年 2 月 13 日
編集済み: randerss simil 2021 年 2 月 13 日
%if true
m = 2
n = 1.5
Y = m*x.^n;
k = polyval(x,Y)
First use polyval for the equation and then apply polyfit

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by