Curve fitting with a constrained y value to Zero
이전 댓글 표시
I need to fit a curve ( Second-order polynomial ) with a constraint that a specific y-value equal to Zero
4.4 2.367224698
21.1 0
37.8 -1.857318083
54.4 -3.276015126
X & Y values as an example attached X = [ 4.4 21.1 37.8 54.4 ]
I want to fit the cuve where the y-value at x= 21.1 equal to zero
I am new to matlab and i have tried Curve fitting toolbox, I think it is not provided as a constraint in the toolbox
채택된 답변
추가 답변 (2개)
Serhii Tetora
2020년 8월 13일
편집: Serhii Tetora
2020년 8월 13일
clear;close;clc
x = [4.4 21.1 37.8 54.4 ];
y = [2.367224698 0 -1.857318083 -3.276015126];
w = [1 1000 1 1];
[xData, yData, weights] = prepareCurveData( x, y, w );
% Set up fittype and options.
ft = fittype( 'poly2' );
opts = fitoptions( 'Method', 'LinearLeastSquares' );
opts.Weights = weights;
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
h = plot( fitresult, xData, yData, 'o' );
legend( h, 'y vs. x', 'fit', 'Location', 'NorthEast');
% Label axes
xlabel('x');
ylabel('y');
grid on
Using lsqlin,
x0=21.1;
x = [4.4 37.8 54.4 ].';
y = [2.367224698 -1.857318083 -3.276015126].';
p=lsqlin(x.^[2,1,0],y,[],[],x0.^[2,1,0],0)
Check:
>> polyval(p,21.1)
ans =
-4.4409e-16
댓글 수: 2
Khaled Bahnasy
2020년 8월 13일
The approximation error given by my approach is at the limit of floating point precision. It's meaningless to aspire beyond that. The value 21.1 doesn't even have an exact representation in a binary floating point computer. To 47 decimal places, the number that the computer is really holding when you enter x0=21.1 is,
'21.10000000000000142108547152020037174224853515625'
카테고리
도움말 센터 및 File Exchange에서 Linear Predictive Coding에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!