From: Panagiotis on
Hello everyone,

I m using "fmincon" to optimise a problem. The function evaluations have to be done by an external program which produces an output file that can be read by "fun" and "nonlcon". I wonder if this external program has to be called both by "fun" and "nonlcon" functions, or whether I can only call it once in "fun" and then just read the generated output file in "nonlcon". This will save a lot of computational time...

I think to answer that we need to know whether "nonlcon" is called at the same time, before or after "fun".

thank you in advance for any help

Panos
From: Gene on
"Panagiotis " <panos.giannakakis(a)gmail.com> wrote in message <i43c29$c1a$1(a)fred.mathworks.com>...
> Hello everyone,
>
> I m using "fmincon" to optimise a problem. The function evaluations have to be done by an external program which produces an output file that can be read by "fun" and "nonlcon". I wonder if this external program has to be called both by "fun" and "nonlcon" functions, or whether I can only call it once in "fun" and then just read the generated output file in "nonlcon". This will save a lot of computational time...
>
> I think to answer that we need to know whether "nonlcon" is called at the same time, before or after "fun".
>
> thank you in advance for any help
>
> Panos

Hi Panos:

You can use the Matlab procedures 'assignin' and 'evalin' (though this makes computer science folks twitch). You assume that before each call to 'nonlcon' there has been a call to 'fun' (with the same independent vars). In 'fun' you assign appropriate variables in the 'base' workspace and in the subsequent call to 'nonlcon' you use 'evalin' to retrieve these. Be very careful to use appropriate unique names for the assignin/evalin variables, lest you clobber something in the 'base' workspace.

Have fun

gene
From: Panagiotis on
"Gene " <ecliff(a)vt.edu> wrote in message <i43dop$cg$1(a)fred.mathworks.com>...
> "Panagiotis " <panos.giannakakis(a)gmail.com> wrote in message <i43c29$c1a$1(a)fred.mathworks.com>...
> > Hello everyone,
> >
> > I m using "fmincon" to optimise a problem. The function evaluations have to be done by an external program which produces an output file that can be read by "fun" and "nonlcon". I wonder if this external program has to be called both by "fun" and "nonlcon" functions, or whether I can only call it once in "fun" and then just read the generated output file in "nonlcon". This will save a lot of computational time...
> >
> > I think to answer that we need to know whether "nonlcon" is called at the same time, before or after "fun".
> >
> > thank you in advance for any help
> >
> > Panos
>
> Hi Panos:
>
> You can use the Matlab procedures 'assignin' and 'evalin' (though this makes computer science folks twitch). You assume that before each call to 'nonlcon' there has been a call to 'fun' (with the same independent vars). In 'fun' you assign appropriate variables in the 'base' workspace and in the subsequent call to 'nonlcon' you use 'evalin' to retrieve these. Be very careful to use appropriate unique names for the assignin/evalin variables, lest you clobber something in the 'base' workspace.
>
> Have fun
>
> gene

Hello gene and thanks for your prompt reply

So 'fun' is always executed before 'nonlcon' for every evaluation of the 'x' vector.
However, I don't need to use the extraction to workspace as I just read the results from the output file generated by the external program.
From: Alan Weiss on
On 8/13/2010 7:59 AM, Panagiotis wrote:
> Hello everyone,
>
> I m using "fmincon" to optimise a problem. The function evaluations have
> to be done by an external program which produces an output file that can
> be read by "fun" and "nonlcon". I wonder if this external program has to
> be called both by "fun" and "nonlcon" functions, or whether I can only
> call it once in "fun" and then just read the generated output file in
> "nonlcon". This will save a lot of computational time...
>
> I think to answer that we need to know whether "nonlcon" is called at
> the same time, before or after "fun".
>
> thank you in advance for any help
>
> Panos

There is a technique in this thread that enables you to evaluate the
function just once, no matter which function calls it first:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/269936#707304

Alan Weiss
MATLAB mathematical toolbox documentation
From: Panagiotis on
Alan Weiss <aweiss(a)mathworks.com> wrote in message <i43f4h$ptq$1(a)fred.mathworks.com>...
> On 8/13/2010 7:59 AM, Panagiotis wrote:
> > Hello everyone,
> >
> > I m using "fmincon" to optimise a problem. The function evaluations have
> > to be done by an external program which produces an output file that can
> > be read by "fun" and "nonlcon". I wonder if this external program has to
> > be called both by "fun" and "nonlcon" functions, or whether I can only
> > call it once in "fun" and then just read the generated output file in
> > "nonlcon". This will save a lot of computational time...
> >
> > I think to answer that we need to know whether "nonlcon" is called at
> > the same time, before or after "fun".
> >
> > thank you in advance for any help
> >
> > Panos
>
> There is a technique in this thread that enables you to evaluate the
> function just once, no matter which function calls it first:
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/269936#707304
>
> Alan Weiss
> MATLAB mathematical toolbox documentation

Alan thank you that would be ideal!!

How would I then call the "ObjectiveAndConstraints" function with fmincon?

I mean, what would be the syntax of fmincon?

Panos