for loop help - solving least squares

3 views (last 30 days)
gm
gm on 29 Apr 2015
Commented: John D'Errico on 29 Apr 2015
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 Comment
John D'Errico
John D'Errico on 29 Apr 2015
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.

Sign in to comment.

Answers (0)

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!