Hello , I am dealing with linear least square regression

1 回表示 (過去 30 日間)
Charitha Heshan
Charitha Heshan 2018 年 3 月 16 日
コメント済み: Charitha Heshan 2018 年 3 月 18 日
.I successfully found the coefficients for the quadratic function as follows.
function [a2,a1,a0] = QuadraticRegression (x,y)
x=[10 15 25 40 50 55];
y=[94 116 147 183 215 220];
n = length (x)
sx = sum(x)
sy = sum(y)
sx2 = sum(x.^2)
sx3 = sum(x.^3)
sx4 = sum(x.^4)
sxy = sum(x.*y)
sx2y= sum(x.*x.*y)
A = [ n sx sx2; sx sx2 sx3;sx2 sx3 sx4]
b = [sy;sxy;sx2y]
w= A\b
a2 = w(3)
a1 = w(2)
a0 = w(1)
% code
end*
func(y) = -0.0170 x.^2 + 3.8870 x + 59.0062
now i'm suppose to fit the above data into a power function as follows : y = Q (x.^M) Where Q and M are coefficients.
and went through Youtube and google before i posted my question here. I see no method mentions in the any of the resources. Please give me some clues. Thanks
  1 件のコメント
David Goodmanson
David Goodmanson 2018 年 3 月 16 日
Hi Charitha,
try taking the logarithm of both sides and using the rule for log(C*x^m) in terms of log(C), m and log(x). That should give you an equation you can fit for two new arrays, logy = log(y) vs. logx = log(x).

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

採用された回答

Torsten
Torsten 2018 年 3 月 16 日
編集済み: Torsten 2018 年 3 月 16 日
y = Q*x^M => log(y) = log(Q) + M*log(x)
Thus take "log" of your x- and y-data and fit them by a linear function
y~ = a+b*x~
where
y~=log(y) and x~=log(x).
Once you have determined a and b, Q=exp(a) and M=b.
Another possibility is to use "lsqcurevfit" directly on the nonlinear function y = Q*x^M.
This will give slightly different fit parameters for Q and M because taking the log of x and y and making a linear fit as suggested above somehow distorts the data.
Best wishes
Torsten.

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by