The quiz I met first gave me an Logistic model:
And ask me to linearize it, then evaluate the value of a
and k
according to the data it gave( in this subject L
is took as 3000
). I finished that, but got into trouble in the second subject which asked me to do a non-linear-regression with a
and k
's value evaluated in the first subject. Here's my code:
function y = func(const, t)
y = const(1)./(1 + const(2)*exp(-const(3)*t));
end
t = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
y = [43.65, 109.86, 187.21, 312.67, 496.58, 707.65 , ...
960.25, 1238.75, 1560, 1824.29, 2199, 2438.89, 2737.71];
yAss = log ((3000 ./ y) - 1);
p = polyfit (t, yAss, 1);
a = exp (1) ^ (p(2));
k = -p(1);
beta0 = [3000, a, k];
beta = nlinfit (t, yAss, @func, beta0);
yAfter = beta(1) ./ (1 + beta(2) * exp (-beta(3) * t));
yCompare = 3000 ./ (1 + a * exp (-k * t));
scatter (t, y); hold on;
plot (t, yAfter, 'r');
plot (t, yCompare);
And what it gave:
The red curve is generated with the value returned by nlinfit
, Anyone could tell me what is wrong?