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: Contraint in curve fitting optimization
Replies: 2   Last Post: Sep 2, 2013 5:28 AM

Advanced Search

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

Posts: 1,206
Registered: 11/27/08
Re: Contraint in curve fitting optimization
Posted: Sep 1, 2013 11:41 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 9/1/2013 3:16 AM, Kapila Bandara wrote:
> i want to know how can i put constraint in curve fitting optimization function.
>
> For example i want to give constraint as 0<beta <1 in following function.
>
> .......................................................
> function [estimates, model] = fitcurvedemo(xdata, ydata)
> % Call fminsearch with a random starting point.
> start_point = rand(1,4 );
> model = @expfun;
> estimates = fminsearch(model, start_point);
> % expfun accepts curve parameters as inputs, and outputs sse,
> % the sum of squares error for A*exp(-lambda*xdata)-ydata,
> % and the FittedCurve. FMINSEARCH only needs sse, but we want
> % to plot the FittedCurve at the end.
> function [sse, FittedCurve] = expfun(params)
> A = params(1);
> lambda = params(2);
> B=params(3);
> beta=params(4);
> FittedCurve = (A .* exp(-lambda * xdata) +B.*xdata.^beta);
> ErrorVector = FittedCurve - ydata;
> sse = sum(ErrorVector .^ 2);
> end
> end


You can use fmincon instead of fminsearch if you have Optimization Toolbox.

Or, for this simple constraint, use exp(-beta^2) where you currently
have beta in FittedCurve. exp(-beta^2) is always between 0 and 1. I
recommend you start beta out with a value of 1, not something close to 0
or higher than 2.

Alan Weiss
MATLAB mathematical toolbox documentation



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.