Matlab Fmincon Optimization Example: Constrained Box Volume

  Рет қаралды 38,305

AlphaOpt

AlphaOpt

Күн бұрын

Пікірлер: 35
@EngrHafizQasimAli
@EngrHafizQasimAli 3 жыл бұрын
Thank you very much for making a video on this simple optimization example, for beginner learners like me.
@chinthakawk
@chinthakawk 2 жыл бұрын
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
@omartalal2554
@omartalal2554 3 жыл бұрын
thanks a lot for this great explination .... can I have the code because i faced an error when excute it .
@johnlloydcalisi3257
@johnlloydcalisi3257 4 жыл бұрын
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 .
@gamzebalkan6432
@gamzebalkan6432 6 жыл бұрын
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!
@jauharalikhan6658
@jauharalikhan6658 4 жыл бұрын
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 4 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐💐
@basirbarmaki1564
@basirbarmaki1564 5 жыл бұрын
That is greatful video Can I help me the a method constrained optimization or a level comparison? How can fined best worst average
@alielectricalelectronicsan2092
@alielectricalelectronicsan2092 4 жыл бұрын
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 4 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐💐
@kewjx44
@kewjx44 4 жыл бұрын
Is this a quadratic type objective function with nonlinear constraint
@beoptimistic5853
@beoptimistic5853 4 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐
@MrZvensk
@MrZvensk 6 жыл бұрын
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
@ahmedsultan36
@ahmedsultan36 6 жыл бұрын
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
@anujagrawal1036
@anujagrawal1036 4 жыл бұрын
why did you used so many square bracket inside fmincon . how many square bracket are needed??
@beoptimistic5853
@beoptimistic5853 4 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐💐
@bipinkarki9664
@bipinkarki9664 3 жыл бұрын
HOW TO FIND THE OBJECTIVE FUNCTION USING TWO VARIABLES?
@ramiz2999
@ramiz2999 5 жыл бұрын
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?
@ns3lover779
@ns3lover779 6 жыл бұрын
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
@kevindsilva1344
@kevindsilva1344 4 жыл бұрын
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 4 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐💐
@johnlloydcalisi3257
@johnlloydcalisi3257 4 жыл бұрын
thanks
@beoptimistic5853
@beoptimistic5853 4 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐💐
MATLAB Nonlinear Optimization with fmincon
14:26
APMonitor.com
Рет қаралды 243 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
Python Scipy Optimization Example: Constrained Box Volume
5:15
Constrained Optimization: Intuition behind the Lagrangian
10:49
Applied Optimization - Matlab 'fminsearch' with Two Variables
9:23
Constrained Optimization Problems with MATLAB
13:00
Dr. Harish Garg
Рет қаралды 16 М.
Transformers (how LLMs work) explained visually | DL5
27:14
3Blue1Brown
Рет қаралды 4,2 МЛН
SciPy Beginner's Guide for Optimization
11:03
APMonitor.com
Рет қаралды 300 М.
Regression with MATLAB fmincon
17:52
APMonitor.com
Рет қаралды 30 М.
7 Outside The Box Puzzles
12:16
MindYourDecisions
Рет қаралды 13 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН