second order data fitting using least squares

30 ビュー (過去 30 日間)
Sangmin
Sangmin 2019 年 1 月 17 日
編集済み: Torsten 2019 年 1 月 18 日
hi
I am trying to fitting the data
I want to fitting the data 1 by least square fitting it to a quadratic function around the position of maximum data2(*)
f(x) = a(x-x0)^2 + b(x-x0) + c
where C is an additive constant C = f(x0) = 1.
I used several method (ex data fitting tool...) but failed
If you konw how to solve, pleast let me know
untitled.jpg
  2 件のコメント
Torsten
Torsten 2019 年 1 月 17 日
x0 is a fitting parameter or set to a fixed value ?
Sangmin
Sangmin 2019 年 1 月 18 日
編集済み: Sangmin 2019 年 1 月 18 日
x0 is one of the data with the largest value.
x = [0.81 0.85 0.91 1.00 1.17 1.33 1.36 1.37 1.39 1.40 1.42]
y = [0.58 0.69 0.81 0.93 1 0.91 0.84 0.80 0.74 0.67 0.59]
x0 is maximum point (1.17 1)
I want to fit the quadratic curve through x0

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

回答 (2 件)

Torsten
Torsten 2019 年 1 月 18 日
編集済み: Torsten 2019 年 1 月 18 日
x = [0.81 0.85 0.91 1.00 1.17 1.33 1.36 1.37 1.39 1.40 1.42];
y = [0.58 0.69 0.81 0.93 1 0.91 0.84 0.80 0.74 0.67 0.59];
x0 = x(5);
y0 = y(5);
xtrans = x - x0;
ytrans = y - y0;
xtrans = xtrans.';
ytrans = ytrans.';
%mat = [sum(xtrans.^4) sum(xtrans.^3);sum(xtrans.^3) sum(xtrans.^2)];
%rhs = [sum(xtrans.^2.*ytrans); sum(xtrans.*ytrans)];
mat = [xtrans.^2 xtrans];
rhs = ytrans;
sol = mat\rhs;
a = sol(1);
b = sol(2);
fun = @(x)a*(x-x0).^2+b*(x-x0)+y0;
yfit = fun(x);
plot(x,y,x,yfit)

Akira Agata
Akira Agata 2019 年 1 月 18 日
Another possible solution:
x = [0.81 0.85 0.91 1.00 1.17 1.33 1.36 1.37 1.39 1.40 1.42]';
y = [0.58 0.69 0.81 0.93 1 0.91 0.84 0.80 0.74 0.67 0.59]';
x0 = x(5);
y0 = y(5);
modelfun = @(a,x) a(1)*(x - x0).^2 + a(2)*(x - x0) + y0;
beta0 = [-1 1]; % Initial guess
mdl = fitnlm(x,y,modelfun,beta0);
xq = linspace(min(x),max(x))';
figure
scatter(x,y)
hold on
plot(xq,predict(mdl,xq))
fitting.png

カテゴリ

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