Borrar filtros
Borrar filtros

Data Curve Fitting Not Fitting Third Point?

2 visualizaciones (últimos 30 días)
Kelly McGuire
Kelly McGuire el 20 de Feb. de 2019
Respondida: Kelly McGuire el 20 de Feb. de 2019
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])

Respuestas (1)

Kelly McGuire
Kelly McGuire el 20 de Feb. de 2019
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])

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by