I was wondering if there exists code to (auto) generate the required input files for the constraints and the objective function to use with fmincon. Specifically, I want to enter the following in a text file:

minimize f(x)
subject to
g(x) <= 0
h(x) = 0

where f(x), g(x) and h(x) are (possibly nonlinear) functions of several variables denoted by x(1), x(2), ....

and I want the corresponding objective function and constraint files including the gradients and the hessians to be formed automatically.

Thank you,

Angie

Subject: How to generate input files for fmincon using regular mathematical program syntax

"Angie" <angie11tr@yahoo.com> wrote in message <hj2n40$fg4$1@fred.mathworks.com>...
> Hi:
>
> I was wondering if there exists code to (auto) generate the required input files for the constraints and the objective function to use with fmincon. Specifically, I want to enter the following in a text file:
>
> minimize f(x)
> subject to
> g(x) <= 0
> h(x) = 0

What you've shown in this example "text file" gives no information about the definitions of f(), g(), or h(). Where would that info come from?

Subject: How to generate input files for fmincon using regular mathematical program syntax

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hj2q1t$l1j$1@fred.mathworks.com>...
> "Angie" <angie11tr@yahoo.com> wrote in message <hj2n40$fg4$1@fred.mathworks.com>...
> > Hi:
> >
> > I was wondering if there exists code to (auto) generate the required input files for the constraints and the objective function to use with fmincon. Specifically, I want to enter the following in a text file:
> >
> > minimize f(x)
> > subject to
> > g(x) <= 0
> > h(x) = 0
>
> What you've shown in this example "text file" gives no information about the definitions of f(), g(), or h(). Where would that info come from?

Sorry for the confusion, I simply simplified the expressions into f(x), g(x), h(x). As an example consider the following mathematical program:

I see. Well, I don't think code already exists, although you could check the File Exchange.

If you wanted to code it yourself, you could fairly easily use fgetl() and regexp() to parse the file and find the expressions for f,g, and h as strings. However, you would then probably need the symbolic toolbox to do the symbolic differentiation to get the expression for the gradient/Hessian.

In any case, this is not normally the way you would want to do things. It is not typically efficient to implement the objective function, constraints, and gradients as directly given by their symbolic expressions.

For example, if your objective function is, like in your example, a quadratic
f(x)=x'*(Q/2)*x and you know you also want to use the analytic gradient
grad(x)=Q*x, then you would not want a file that evaluates these two symbolic expressions separately. You would want a file that is smart enough to first compute the gradient grad(x) and then derive f(x) from the gradient according to
f(x)=x'*grad(x), which is equivalent to x'*Q*x but doesn't require you to evaluate Q*x a second time.

Were you hoping to find a piece of code that recognizes these efficient strategies automatically? Such code would probably border on artifical intelligence, unless it new very specific things ahead of time about the structure of your problem.

Subject: How to generate input files for fmincon using regular mathematical program syntax

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hj3a77$lte$1@fred.mathworks.com>...
> "Angie" <angie11tr@yahoo.com> wrote in message <hj2rvj$liu$1@fred.mathworks.com>...
>
> > Sorry for the confusion, I simply simplified the expressions into f(x), g(x), h(x). As an example consider the following mathematical program:
> >
> > minimize a*x(1)^2 + b*x(2)^2 + c*x(1)*x(2)
> > subject to
> > - d*x(1)^2 + 1 <= 0
> > - e*x(1)*x(2) + 2 <= 0
> > - x(1) <= 0
> > - x(2) <= 0
> >
> > in which I don't have any equalities for simplicity. a, b, c, d, e will be symbolic parameters. I want my text file to contain the above mathematical model as it is. Does this answer your question?
> =========================
>
> I see. Well, I don't think code already exists, although you could check the File Exchange.
>
> If you wanted to code it yourself, you could fairly easily use fgetl() and regexp() to parse the file and find the expressions for f,g, and h as strings. However, you would then probably need the symbolic toolbox to do the symbolic differentiation to get the expression for the gradient/Hessian.
>
> In any case, this is not normally the way you would want to do things. It is not typically efficient to implement the objective function, constraints, and gradients as directly given by their symbolic expressions.
>
> For example, if your objective function is, like in your example, a quadratic
> f(x)=x'*(Q/2)*x and you know you also want to use the analytic gradient
> grad(x)=Q*x, then you would not want a file that evaluates these two symbolic expressions separately. You would want a file that is smart enough to first compute the gradient grad(x) and then derive f(x) from the gradient according to
> f(x)=x'*grad(x), which is equivalent to x'*Q*x but doesn't require you to evaluate Q*x a second time.
>
> Were you hoping to find a piece of code that recognizes these efficient strategies automatically? Such code would probably border on artifical intelligence, unless it new very specific things ahead of time about the structure of your problem.

Thank you for your answer. I have several models and each time I use fmincon I have to update everything from scratch. It is easy to make mistakes with copy and paste and this was the main reason for my post. I tried to come up with my own piece of code to do what I want but it gets messy. I was hoping maybe that such code exists. Maybe I will look more into what I did and if I come up with something I will post again.

Thanks again...

Subject: How to generate input files for fmincon using regular mathematical