second order data fitting using least squares

31 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Least Squares 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by