필터 지우기
필터 지우기

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 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