Thread Subject:
Provide input and run fmincon on the same function file.

Subject: Provide input and run fmincon on the same function file.

From: sparky

Date: 1 Jul, 2012 03:05:14

Message: 1 of 5

Hi,
I am trying to use the optimization tool "fmincon".
the syntax for the command is
>> x=fmincon(@opt.m,x0,lb,ub)
%where,
% x is the variable to be optimized.
% opt.m runs the function which is to be minimized
% x0 is the initial value of x for the iteration process
% lb,ub are the lower and upper bounds of x.

now the function file "opt.m" has the definition as;
>> function J=file(x0)
a;b;
J=a*b-x0;

I am using the fmincon command from my base file "input.m"
my problem is that to run the file "opt.m" I want to provide the values of "a" and "b" from "input.m".
how can i do that, since in order to use the fmincon command on the file "opt.m", the only inputs i can send to "opt.m" is x0.

I hope my query is clear.

Subject: Provide input and run fmincon on the same function file.

From: Bruno Luong

Date: 1 Jul, 2012 08:54:07

Message: 2 of 5

http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-7.html

Bruno

Subject: Provide input and run fmincon on the same function file.

From: Matt J

Date: 1 Jul, 2012 14:01:09

Message: 3 of 5

"sparky" wrote in message <jsoepa$qog$1@newscl01ah.mathworks.com>...
> Hi,
> I am trying to use the optimization tool "fmincon".
> the syntax for the command is
> >> x=fmincon(@opt.m,x0,lb,ub)
==================

Check the documentation again. Lb and ub are not input here with the correct syntax.

Subject: Provide input and run fmincon on the same function file.

From: Steven_Lord

Date: 2 Jul, 2012 03:51:39

Message: 4 of 5



"sparky " <leoanish01@yahoo.com> wrote in message
news:jsoepa$qog$1@newscl01ah.mathworks.com...
> Hi,
> I am trying to use the optimization tool "fmincon".
> the syntax for the command is
>>> x=fmincon(@opt.m,x0,lb,ub)

Incorrect. There are two major problems with your attempt.

1) Specify the function as @opt; you don't use the extension when you call
the function normally, so you shouldn't use it when you define a function
handle to that function.

2) You can't simply leave out input arguments that you don't want to specify
and expect FMINCON to "figure it out." As stated in the help for FMINCON, if
you want to skip A, b, Aeq, and/or beq you need to specify them as [].

> now the function file "opt.m" has the definition as;
>>> function J=file(x0)
> a;b;
> J=a*b-x0;
>
> I am using the fmincon command from my base file "input.m"
> my problem is that to run the file "opt.m" I want to provide the values of
> "a" and "b" from "input.m".
> how can i do that, since in order to use the fmincon command on the file
> "opt.m", the only inputs i can send to "opt.m" is x0.

Bruno directed you to the correct documentation page that answers this
question.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Provide input and run fmincon on the same function file.

From: sparky

Date: 13 Jul, 2012 03:41:39

Message: 5 of 5

Thanks Bruno.
Got it

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
extra parameters Matt J 1 Jul, 2012 09:55:50
rssFeed for this Thread

Contact us