Filter löschen
Filter löschen

second order data fitting using least squares

31 Ansichten (letzte 30 Tage)
Sangmin
Sangmin am 17 Jan. 2019
Bearbeitet: Torsten am 18 Jan. 2019
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 Kommentare
Torsten
Torsten am 17 Jan. 2019
x0 is a fitting parameter or set to a fixed value ?
Sangmin
Sangmin am 18 Jan. 2019
Bearbeitet: Sangmin am 18 Jan. 2019
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

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Torsten
Torsten am 18 Jan. 2019
Bearbeitet: Torsten am 18 Jan. 2019
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 am 18 Jan. 2019
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

Kategorien

Mehr zu Least Squares finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by