Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: regarding fminsearch in Matlab

Subject: regarding fminsearch in Matlab

From: econgrad

Date: 18 Jul, 2008 04:44:16

Message: 1 of 5

Hi,
I need to put a simple constraint and use fminsearch.
min f(x) subject to sum(x)=<1 (or preferably -1<sum(x)<1)
where x is a vector.
I can use fmincon, but it does not work well for my problem at. Any feedback would be greatly appreciated
Thanks

Subject: regarding fminsearch in Matlab

From: Bruno Luong

Date: 18 Jul, 2008 06:00:24

Message: 2 of 5

econgrad <hammadq80@gmail.com> wrote in message
<5111638.1216356287372.JavaMail.jakarta@nitrogen.mathforum.org>...
> Hi,
> I need to put a simple constraint and use fminsearch.
> min f(x) subject to sum(x)=<1 (or preferably -1<sum(x)<1)
> where x is a vector.
> I can use fmincon, but it does not work well for my
problem at. Any feedback would be greatly appreciated
> Thanks

Change the variables: pick one of your variables and replace
by the sum. Alternatively you can also use the 'cumsum'
variable. In other word, work on new multi-variable "y" with
this linear transformation y=P*x

minimize g(y) := f(inv(P)*y)

P = [1 0 ... 0
     0 1 ....0
     ...
     0 0 0 1 0
     1 1 1 1 1] % last variable is replaces by the sum

Or

P = [1 0 ... 0
     1 1 ... 0
     ...
     1 1 ... 1 0
     1 1 1 1 1 1]

Now the sum constraint on x becomes bound constraint on last
variable on y.: -1<=y(n)<=1

Use any bound constraint minimization algorithm, such as
this one
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8277

Bruno

Subject: regarding fminsearch in Matlab

From: John D'Errico

Date: 18 Jul, 2008 08:23:02

Message: 3 of 5

econgrad <hammadq80@gmail.com> wrote in message
<5111638.1216356287372.JavaMail.jakarta@nitrogen.mathforum.org>...
> Hi,
> I need to put a simple constraint and use fminsearch.
> min f(x) subject to sum(x)=<1 (or preferably -1<sum(x)<1)
> where x is a vector.
> I can use fmincon, but it does not work well for my problem at. Any
feedback would be greatly appreciated
> Thanks

(Why did fmincon fail to work well?)

Are there any other constraints on the problem?
If not, then you can easily enough transform this
into a bound constrained problem by a simple
transformation.

Suppose you have n variables, x1,...,xn.

Leave the first n-1 variables unchanged, but
your n'th variable will now become the sum of
all n unknowns. I'll call ir xsum. Compute the
actual value of xn inside your objective function
as

   xsum - x1 - x2 - x3

Now you can simply place a bound constraint
(both lower and upper bounds) on the sum of
the variables.

If you are unhappy with how fmincon worked,
then you can now use fminsearchbnd on this
simple bound constrained system. You can
even have bounds on the first n-1 unknowns.
The only problem is you will not be able to put
bounds on xn.

You can find fminsearchbnd on the file exchange.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?
objectId=8277&objectType=file

John

Subject: regarding fminsearch in Matlab

From: econgrad

Date: 22 Jul, 2008 05:40:08

Message: 4 of 5

Thanks abunch Bruno

Subject: regarding fminsearch in Matlab

From: econgrad

Date: 22 Jul, 2008 05:43:55

Message: 5 of 5

Thanks John,
I am not sure why fmincon failed. No, I dont have any other constraints. I think that fminsearch and fmincon are based on very different algorithms and fmincon seems to get stuck with some local/flat area much more easily. Based on my experience fminsearch works better.
Thanks for your input. It was very helpful

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics