Data Curve Fitting Not Fitting Third Point?

7 ビュー (過去 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 Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by