Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: least-squares fitting: Setting up the objective function
Replies: 3   Last Post: Jan 31, 2014 9:50 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
GS

Posts: 22
Registered: 4/19/12
least-squares fitting: Setting up the objective function
Posted: Jan 31, 2014 8:04 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am working on a least-squares fitting problem and I am looking at the lsqnonlin() example below. I have a similar problem. Except, the "k" here is the data I have. How do I setup the objective function if I have to pass this data to the objective function?

It is not apparent in this example where the summation is occurring


****************
Step 1: Write a file myfun.m that computes the objective function values.
function F = myfun(x)
k = 1:10;
F = 2 + 2*k-exp(k*x(1))-exp(k*x(2));

Step 2: Call the nonlinear least-squares routine.
x0 = [0.3 0.4]; % Starting guess
[x,resnorm,res,eflag,output1] = lsqnonlin(@myfun,x0); % Invoke optimizer
****************

Source: http://www.mathworks.com/help/optim/ug/nonlinear-least-squares-with-full-jacobian.html

Thanks.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.