for loop help - solving least squares

3 次查看(过去 30 天)
gm
gm 2015-4-29
I have unique observations (t,y) stored in the columns of a 2x80 sized array called data (where the top row is t and the bottom row is y and each column is a new observation).
i have a function
y(t) = a*exp(t*k*a)/(1+exp(t*k*a)
and i want to iterate through different values of a,k find the error from the observed y and then do square the difference and store it in an array that is 1250x20 which i call 'ls'.
for a = 700:1:2150
for k = 0.000001:0.000001:0.00002
error = zeros(size(a),size(k));
for every (t,y) observation in data
error = ((a*exp(t*k*a)/(1+exp(t*k*a)))-y)^2
end
end
end
thanks!
  1 个评论
John D'Errico
John D'Errico 2015-4-29
Is there a good reason why you want to use such a poor scheme to estimate these parameters? Ok, let me ask, is the ANY reason at all, besides the possibility that you have never heard about nonlinear regression?
This is simple nonlinear regression problem. So tools like lsqnonlin, nlinfit, lsqcurvefit, and the curve fitting toolbox are designed to solve the problem, and to do it FAR more efficiently than the scheme you have posed. Plus, there are many other tools one can use, for example, my own fminspleas, from the file exchange.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by