Data Curve Fitting Not Fitting Third Point?

조회 수: 1 (최근 30일)
Kelly McGuire
Kelly McGuire 2019년 2월 20일
답변: Kelly McGuire 2019년 2월 20일
Any ideas why it appears the third data point is not being fit?
xdata = [1;10;100];
ydata = [0;0;0.3];
fun = @(x,xdata)(1./(1+(x(1)./xdata).^x(2)));
lb = [1,1];
ub = [1000,5];
x0 = [50,2];
x = lsqcurvefit(fun,x0,xdata,ydata,lb,ub)
figure
hold on
plot(xdata,ydata,'ko');
xlim([0 200]);
xlabel('Concentration','FontWeight','bold');
ylim([0 1]);
ylabel('Average Mortality','FontWeight','bold');
box off
y = 0:200;
plot(1./(1+(x(1)./y)).^x(2))
xlim([0 200])
ylim([0 1])

답변 (1개)

Kelly McGuire
Kelly McGuire 2019년 2월 20일
Fixed the problem. In the second plot, my x(2) was in the wrong term. It should have been brought into the left parthensis. Here is the correct code:
xdata = [1;10;100];
ydata = [0;0;0.3];
fun = @(x,xdata)(1./(1+(x(1)./xdata).^x(2)));
lb = [170,1];
ub = [200,2];
x0 = [180,1.6];
%x = lsqcurvefit(fun,x0,xdata,ydata,lb,ub)
opts = optimset('MaxFunEvals',1E+4, 'MaxIter',1E+4 );
x = fminsearch(@(x) norm(ydata - fun(x,xdata)), x0, opts)
figure
hold on
plot(xdata,ydata,'ko');
xlim([0 200]);
xlabel('Concentration','FontWeight','bold');
ylim([0 1]);
ylabel('Average Mortality','FontWeight','bold');
box off
y = 0:600;
plot(1./(1+(x(1)./y).^x(2)))
xlim([0 200])
ylim([0 1])

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by