Matlab Fmincon Optimization Example: Constrained Box Volume

Ғылым және технология

This video shows how to perform a simple constrained optimization problem with fmincon in Matlab. This video is part of an introductory series on optimization.

Пікірлер: 35

  • @EngrHafizQasimAli
    @EngrHafizQasimAli3 жыл бұрын

    Thank you very much for making a video on this simple optimization example, for beginner learners like me.

  • @basirbarmaki1564
    @basirbarmaki15645 жыл бұрын

    That is greatful video Can I help me the a method constrained optimization or a level comparison? How can fined best worst average

  • @omartalal2554
    @omartalal25543 жыл бұрын

    thanks a lot for this great explination .... can I have the code because i faced an error when excute it .

  • @gamzebalkan6432
    @gamzebalkan64326 жыл бұрын

    Thank you! Do you know how to optimize dynamic systems with optimization toolbox?

  • @abemartin6945

    @abemartin6945

    6 жыл бұрын

    Gamze Balkan for dynamic optimization I would recommend the APMonitor optimization package: apmonitor.com

  • @gamzebalkan6432

    @gamzebalkan6432

    6 жыл бұрын

    I will look over it, thanks a lot!

  • @kewjx44
    @kewjx444 жыл бұрын

    Is this a quadratic type objective function with nonlinear constraint

  • @beoptimistic5853

    @beoptimistic5853

    3 жыл бұрын

    kzread.info/dash/bejne/ioR3yamNaaXSorQ.html 💐💐💐💐💐

  • @johnlloydcalisi3257
    @johnlloydcalisi32574 жыл бұрын

    what is the symbol used before the repeated terms objective and constraints?

  • @anujagrawal1036

    @anujagrawal1036

    4 жыл бұрын

    @ ,it is used to denote a pointer(or address) to the function in file

  • @alielectricalelectronicsan2092

    @alielectricalelectronicsan2092

    4 жыл бұрын

    @@anujagrawal1036 A.o.A sir how can we solve non linear problems in matlab . I only now how to solve the linear Problems in matlab Can you provide me some help in this .

  • @jauharalikhan6658
    @jauharalikhan66583 жыл бұрын

    i have wrote the different function in different files but this error occurs Not enough input arguments. Error in calVolume (line 3) len = x(1);

  • @beoptimistic5853

    @beoptimistic5853

    3 жыл бұрын

    kzread.info/dash/bejne/ioR3yamNaaXSorQ.html 💐💐💐💐💐💐

  • @ahmedsultan36
    @ahmedsultan366 жыл бұрын

    Hi,I have MATLAB R2016a 'function definitions are not permitted in this context'I think this the version's problem. However, I have tried to find a solution but i couldn't find a proper one.Do you have an idea? Thanks in advance

  • @alphaopt2024

    @alphaopt2024

    6 жыл бұрын

    Ahmed, multiple function definitions in a single file are permitted from Matlab 2016b and onwards. For earlier versions of Matlab you will need to define each function in a separate file.

  • @ahmedsultan36

    @ahmedsultan36

    6 жыл бұрын

    Thanks, One more question. Do you have any recommendation for finding a global minimum Many thanks

  • @alphaopt2024

    @alphaopt2024

    6 жыл бұрын

    Finding a global minimum can be difficult depending on your problem. Starting from many different initial guess values can help to verify that you've found a global optimum. Gradient free methods such as particle swarm or genetic algorithms sometimes work. I've found the Matlab global optimization toolbox to be pretty good if you have access to it: www.mathworks.com/products/global-optimization.html

  • @ahmedsultan36

    @ahmedsultan36

    6 жыл бұрын

    One more question. Is there is a way to plot the iterations for this video or similar to it with 3 variables Thanks

  • @chinthakawk
    @chinthakawk Жыл бұрын

    Works fine in R2021b. % set initial guess values for box dimensions lengthGuess = 1; widthGuess = 1; heightGuess = 1; % load guess values into array x0 = [lengthGuess widthGuess heightGuess]; % call solver to minimize the objective function given the constraint xopt = fmincon(@objective,x0,[],[],[],[],[],[],@constraint,[]) % retrieve optimized box sizing and volume volumeOpt = calcVolume(xopt) % calculate surface area with optimized values just to double check surfaceAreaOpt = calcSurface(xopt) % define function to calculate volume of box function volume = calcVolume(x) length = x(1); width = x(2); height = x(3); volume = length * width * height; end % define function to calculate surface area of box function surfaceArea = calcSurface(x) length = x(1); width = x(2); height = x(3); surfaceArea = 2*length*width + 2*length*height + 2*height*width; end % define objective function for optimization function obj = objective(x) obj = -calcVolume(x); end % define constraint for optimization function [c, ceq] = constraint(x) c = calcSurface(x) - 10; ceq = []; end

  • @alielectricalelectronicsan2092
    @alielectricalelectronicsan20924 жыл бұрын

    A.o.A sir how can we solve non linear problems in matlab . I only now how to solve the linear Problems in matlab Can you provide me some help in this .

  • @beoptimistic5853

    @beoptimistic5853

    3 жыл бұрын

    kzread.info/dash/bejne/ioR3yamNaaXSorQ.html 💐💐💐💐💐💐

  • @MrZvensk
    @MrZvensk6 жыл бұрын

    Tried the code but having a "function error" .. wont run .. saying that nested functions cannot run ..

  • @alphaopt2024

    @alphaopt2024

    6 жыл бұрын

    Peter, for the code to work as shown here box.m needs to be a script, not a function. This is possible in Matlab 2016b or later. If you want it as a nested function, you'll need to adapt the code: www.mathworks.com/help/matlab/matlab_prog/nested-functions.html

  • @MrZvensk

    @MrZvensk

    6 жыл бұрын

    AlphaOpt Thanks for d feedback

  • @bipinkarki9664
    @bipinkarki96643 жыл бұрын

    HOW TO FIND THE OBJECTIVE FUNCTION USING TWO VARIABLES?

  • @anujagrawal1036
    @anujagrawal10364 жыл бұрын

    why did you used so many square bracket inside fmincon . how many square bracket are needed??

  • @beoptimistic5853

    @beoptimistic5853

    3 жыл бұрын

    kzread.info/dash/bejne/ioR3yamNaaXSorQ.html 💐💐💐💐💐💐

  • @johnlloydcalisi3257
    @johnlloydcalisi32574 жыл бұрын

    thanks

  • @beoptimistic5853

    @beoptimistic5853

    3 жыл бұрын

    kzread.info/dash/bejne/ioR3yamNaaXSorQ.html 💐💐💐💐💐💐

  • @kevindsilva1344
    @kevindsilva13444 жыл бұрын

    I didn't understand the constraints part of this, could you explain that? I think your videos are awesome BTW, given a thumbs up for all I've viewed till now.

  • @beoptimistic5853

    @beoptimistic5853

    3 жыл бұрын

    kzread.info/dash/bejne/ioR3yamNaaXSorQ.html 💐💐💐💐💐💐

  • @ns3lover779
    @ns3lover7795 жыл бұрын

    I HAVE WRITE THE SAME CODE BUT I GOT THIS ERROR : xopt = fmincon( @objective,x0,[],[],[],[],[],[],@constraint,[] ) Caused by: Failure in initial objective function evaluation. FMINCON cannot continue.

  • @juansebastianhincapiemonte4663

    @juansebastianhincapiemonte4663

    3 жыл бұрын

    You have to install the optimization toolbox

  • @ramiz2999
    @ramiz29995 жыл бұрын

    Great video. However, I write everything like you and I use MATLAB 2016b: lengthGuess=1; widthGuess=1; heightGuess=1; x0=[lengthGuess widthGuess heightGuess]; xopt=fmincon(@objective,x0,[],[],[],[],[],[],[],@constraint,[]) volumeOpt=calcVolume(xopt) surfaceAreaOpt=calcSurface(xopt) function volume = calcVolume( x ) length=x(1); width=x(2); height=x(3); volume=length*width*height; end function surfaceArea=calcSurface(x) length=x(1); width=x(2); height=x(3); surfaceArea=2*length*width+2*length*height+2*width*height; end function obj=objective(x) obj=-calcVolume(x); end function [c, ceq]=constraint (x) c=calcSurface-10; ceq=[]; end I got this: box Field assignment to a non-structure array object. Error in createOptionFeedback (line 33) options.(stopTestOptions{k}) = []; Error in prepareOptionsForSolver (line 40) optionFeedback = createOptionFeedback(options); Error in fmincon (line 215) [options, optionFeedback] = prepareOptionsForSolver(options, 'fmincon'); Error in box (line 7) xopt=fmincon(@objective,x0,[],[],[],[],[],[],[],@constraint,[]) >> Where is the problem?

Келесі