The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

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



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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.