Search All of the Math Forum:

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

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

Topic: Contraint in curve fitting optimization
Replies: 2   Last Post: Sep 2, 2013 5:28 AM

 Search Thread: Advanced Search

 Messages: [ Previous | Next ]
 Alan Weiss Posts: 1,430 Registered: 11/27/08
Re: Contraint in curve fitting optimization
Posted: Sep 1, 2013 11:41 AM
 Plain Text 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

Date Subject Author
9/1/13 Kapila Bandara
9/1/13 Alan Weiss
9/2/13 Kapila Bandara

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