Results 1 to 8 of 8

Math Help - Matlab optimization help

  1. #1
    Newbie
    Joined
    Jul 2010
    Posts
    4

    Matlab optimization help

    Hello, I need some help with a matlab optimization problem. It is a constrained nonlinear optimization one and it only shows the first iteration, in which there are not Nan or Inf values for the objective function.
    I am thinking it may be because I call a different function inside the objective function, but I am not sure if is a problem or not (I haven't find anything about it).
    The code is very simple. It is the following:

    function[der]=dercorte(a);
    [g1,q]=otra(a)
    r=q;
    der=-abs(((a(1)-g1)*(a(6)-a(7))*a(5)*g1/((a(5)-1)*(1-q*(a(1)-g1*(1-q)))^2)));

    And the function otra is:
    function[g1,q]=otra(a);

    g1=0.9;
    dif=10;
    while dif>0.001
    q = -(-(a(6) * a(5) * a(1)) + (a(6) * a(5) * g1) + (a(5) * a(7) * a(1)) - (a(5) * a(7) * g1) - (a(6) * a(5)) - (a(6) * g1) - a(8) + a(6) + (a(8) * g1) + (a(8) * a(5)) + sqrt((4 * a(6) * a(5) ^ 2 * a(1) * a(7) * g1 - 2 * a(6) * a(5) * a(1) * a(8) * g1 - 2 * a(5) * a(7) * a(1) * a(6) * g1 + 2 * a(5) * a(7) * a(1) * a(8) * g1 + a(6) ^ 2 * a(5) ^ 2 * a(1) ^ 2 - 2 * a(6) ^ 2 * a(5) ^ 2 * a(1) + 2 * a(6) ^ 2 * a(5) * a(1) + a(6) ^ 2 * a(5) ^ 2 * g1 ^ 2 + 2 * a(6) ^ 2 * a(5) ^ 2 * g1 - 2 * a(6) ^ 2 * a(5) * g1 ^ 2 + a(5) ^ 2 * a(7) ^ 2 * a(1) ^ 2 + a(5) ^ 2 * a(7) ^ 2 * g1 ^ 2 + 4 * a(6) * a(5) * a(8) - 2 * a(6) * a(5) ^ 2 * a(8) + 4 * a(6) * g1 * a(8) - 2 * a(6) * g1 ^ 2 * a(8) + 2 * a(8) ^ 2 * g1 * a(5) - 2 * a(6) ^ 2 * a(5) ^ 2 * a(1) * g1 - 2 * a(6) * a(5) ^ 2 * a(1) ^ 2 * a(7) + 2 * a(6) ^ 2 * a(5) * a(1) * g1 - 2 * a(6) * a(5) * a(1) * a(8) + 2 * a(6) * a(5) ^ 2 * a(1) * a(8) - 2 * a(6) * a(5) ^ 2 * g1 ^ 2 * a(7) - 2 * a(6) * a(5) * g1 * a(8) + 2 * a(6) * a(5) * g1 ^ 2 * a(8) - 2 * a(6) * a(5) ^ 2 * g1 * a(8) - 2 * a(5) ^ 2 * a(7) ^ 2 * a(1) * g1 + 2 * a(5) ^ 2 * a(7) * a(1) * a(6) + 2 * a(5) * a(7) * a(1) * a(8) - 2 * a(5) * a(7) * a(1) * a(6) - 2 * a(5) ^ 2 * a(7) * a(1) * a(8) - 2 * a(5) ^ 2 * a(7) * g1 * a(6) + 2 * a(5) * a(7) * g1 ^ 2 * a(6) - 2 * a(5) * a(7) * g1 * a(8) + 2 * a(5) * a(7) * g1 * a(6) - 2 * a(5) * a(7) * g1 ^ 2 * a(8) + 2 * a(5) ^ 2 * a(7) * g1 * a(8) + a(6) ^ 2 * a(5) ^ 2 - 2 * a(6) ^ 2 * a(5) + a(6) ^ 2 * g1 ^ 2 - 2 * a(6) ^ 2 * g1 + a(8) ^ 2 - 2 * a(8) * a(6) - 2 * a(8) ^ 2 * g1 - 2 * a(8) ^ 2 * a(5) + a(6) ^ 2 + a(8) ^ 2 * g1 ^ 2 + a(8) ^ 2 * a(5) ^ 2))) / (a(5) - 1) / (a(6) - a(8)) / (a(1) - g1) / 0.2e1;
    gn=min((((a(2)-a(7))*a(5)-(a(2)-a(6)))/a(3))*a(4)*(1-q),1);
    dif=sqrt((g1-gn)^2);
    g1=gn;
    end
    Can anybody help me please? Thanks!!
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Which function are you using to do the minimisation, and which algorithm have you set it to use?

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Jul 2010
    Posts
    4
    I am using fmincon and active set, but I also tried with interior point and it is the same. Thanks!
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Maric View Post
    I am using fmincon and active set, but I also tried with interior point and it is the same. Thanks!
    Try 'sqp'

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Jul 2010
    Posts
    4
    Thanks, but I understand that Active set is sqp. I only have three options: Active set, interior point and trust region reflective. Btw, I am using matlab 2009.
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Maric View Post
    Thanks, but I understand that Active set is sqp. I only have three options: Active set, interior point and trust region reflective. Btw, I am using matlab 2009.
    I was worried by what follows when I first saw your objective but ignored it while doing some background research, your objective does not obviously have continuous derivatives (it may have if the "corners" and other pathologies do not occur during the search), and we have the following from the help system:

    Limitations

    fmincon is a gradient-based method that is designed to work on problems where the objective and constraint functions are both continuous and have continuous first derivatives.
    (explains why I never use it, I usually use Nelder-Mead with penalty functions to implement (soft) constraints, or stochastic search of some kind)

    CB
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Maric View Post
    Thanks, but I understand that Active set is sqp. I only have three options: Active set, interior point and trust region reflective. Btw, I am using matlab 2009.
    The documentation suggests that sqp is able to recover from nan and inf, presumably there is a difference in how Active set abd sqp are implemented as otherwise they would not both be options:

    Active-Set Optimization

    fmincon uses a sequential quadratic programming (SQP) method. In this method, the function solves a quadratic programming (QP) subproblem at each iteration. fmincon updates an estimate of the Hessian of the Lagrangian at each iteration using the BFGS formula (see fminunc and references [7] and [8]).

    fmincon performs a line search using a merit function similar to that proposed by [6], [7], and [8]. The QP subproblem is solved using an active set strategy similar to that described in [5]. fmincon Active Set Algorithm describes this algorithm in detail.

    See also SQP Implementation for more details on the algorithm used.

    Interior-Point Optimization

    This algorithm is described in fmincon Interior Point Algorithm. There is more extensive description in [1], [41], and [9].

    SQP Optimization

    fmincon uses a sequential quadratic programming (SQP) method. In this method, the function solves a quadratic programming (QP) subproblem at each iteration. fmincon updates an estimate of the Hessian of the Lagrangian at each iteration using the BFGS formula (see fminunc and references [7] and [8]).

    fmincon performs a line search using a merit function similar to that proposed by [6], [7], and [8]. The QP subproblem is solved using an active set strategy similar to that described in [5]. fmincon Active Set Algorithm describes this algorithm in detail.

    See also SQP Implementation for more details on the algorithm used.
    You probably don't need it but the online help page is here

    CB
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Newbie
    Joined
    Jul 2010
    Posts
    4
    Thanks, but I think my version is different. I do not have sqp as a different option, my version's help says that active set uses sqp. I will try to update.
    Regarding continuity, derivatives are continuous in all points but one; maybe I have to try more initial conditions.
    Thank you!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Optimization of functions of two variables in Matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: December 8th 2011, 07:47 PM
  2. matlab
    Posted in the Math Software Forum
    Replies: 2
    Last Post: November 24th 2009, 06:51 AM
  3. DSP in Matlab
    Posted in the Math Software Forum
    Replies: 2
    Last Post: November 19th 2009, 12:25 PM
  4. [MATLAB] Optimization - Reduce Step size?
    Posted in the Math Software Forum
    Replies: 0
    Last Post: September 18th 2009, 10:42 PM
  5. MATLAB - Need Help
    Posted in the Math Software Forum
    Replies: 2
    Last Post: May 28th 2008, 12:25 PM

Search Tags


/mathhelpforum @mathhelpforum