Re: Multiple outputs from fmincon



Steve, it is possible that a solution is to remove a semicolon:

function x = try1(q)
x = -(4*q-.5*q^2);
y = -(5*q-23)*x % note: no semicolon


Here's a transcript of the MATLAB run:

[q,fval]=fmincon(@try1,x0,A,b);
Warning: Trust-region-reflective algorithm does not currently solve this type of problem,
using active-set (line search) instead.
> In fmincon at 436

y =

0


y =

-1.3709e-006


y =

-24.0000


y =

-24.0000


Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints were satisfied to within the default value of the constraint tolerance.

Alan Weiss
MATLAB mathematical toolbox documentation

Steve Kasperski wrote:
I am having trouble getting multiple outputs from fmincon. I want to retrieve the solution, the value of the objective function, and a third output which is a function of both the optimal solution as well as the value of the objective function. The simpliest form of this problem I could think of is described below:

function [x,y] = try1(q)
x=-(4*q-.5*q^2);
y=-(5*q-23)*x;

x0=0;
A=1;
b=10;
[q,fval]=fmincon(@try1,x0,A,b);

The solution to this problem is obvious (q=4;x=-8;y=-24), but the only outputs I can get from fmincon are q=4 and fval=x=-8. My real problem is too complicated to discuss here, but y is not something that can be calculated after the values of q and x are determined by fmincon. Therefore I need fmincon to display multiple outputs or have an output function that displays the value of q, x, and y at every iteration and I can just take the ending value for y.

Any suggestions are welcome. Thanks for reading.

Steve
.



Relevant Pages

  • Re: Multiple outputs from fmincon
    ... using active-set instead. ... Local minimum found that satisfies the constraints. ... feasible directions, to within the default value of the function tolerance, ... MATLAB mathematical toolbox documentation ...
    (comp.soft-sys.matlab)
  • Re: doubt on indeterminate forms
    ... I forgot about the other common sci.math question, ... Steve Lord ... with f and g both approaching zero and both ... matlab to investigate the behavior of x^y in the immediate vicinity of the ...
    (comp.soft-sys.matlab)
  • Re: doubt on indeterminate forms
    ... Steve Lord ... with f and g both approaching zero and both ... matlab to investigate the behavior of x^y in the immediate vicinity of the ... million-odd points in the square, z lies between 1 and 0.9998 in value! ...
    (comp.soft-sys.matlab)
  • Re: anonymous function works in command window, not in m file
    ... MATLAB gets confused sometimes when it can't tell how to use a name, so it decided that "max" was a variable. ... You've got the reverse of the problem described in that section, though: that section talks about "poofing" a variable into the workspace after MATLAB has already determined that the identifier is a function. ... was using the command window from inside op2, which is a completely different scope that never had a variable named "max". ... Steve Lord ...
    (comp.soft-sys.matlab)
  • Re: Scheduling problem
    ... - of course quickly reduced through the constraints. ... > This gets into an area that I know nothing about--and I'm sure that Matlab ... The problem as you describe it can be tackled by an integer programming ... easiest method I can think of would be to use a branch and bound approach. ...
    (comp.soft-sys.matlab)