Thank you very much for making a video on this simple optimization example, for beginner learners like me.
@chinthakawk2 жыл бұрын
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
@omartalal25543 жыл бұрын
thanks a lot for this great explination .... can I have the code because i faced an error when excute it .
@johnlloydcalisi32574 жыл бұрын
what is the symbol used before the repeated terms objective and constraints?
@anujagrawal10364 жыл бұрын
@ ,it is used to denote a pointer(or address) to the function in file
@alielectricalelectronicsan20924 жыл бұрын
@@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 .
@gamzebalkan64326 жыл бұрын
Thank you! Do you know how to optimize dynamic systems with optimization toolbox?
@abemartin69456 жыл бұрын
Gamze Balkan for dynamic optimization I would recommend the APMonitor optimization package: apmonitor.com
@gamzebalkan64326 жыл бұрын
I will look over it, thanks a lot!
@jauharalikhan66584 жыл бұрын
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);
@beoptimistic58534 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐💐
@basirbarmaki15645 жыл бұрын
That is greatful video Can I help me the a method constrained optimization or a level comparison? How can fined best worst average
@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 .
@beoptimistic58534 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐💐
@kewjx444 жыл бұрын
Is this a quadratic type objective function with nonlinear constraint
@beoptimistic58534 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐
@MrZvensk6 жыл бұрын
Tried the code but having a "function error" .. wont run .. saying that nested functions cannot run ..
@alphaopt20246 жыл бұрын
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
@MrZvensk6 жыл бұрын
AlphaOpt Thanks for d feedback
@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
@alphaopt20246 жыл бұрын
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.
@ahmedsultan366 жыл бұрын
Thanks, One more question. Do you have any recommendation for finding a global minimum Many thanks
@alphaopt20246 жыл бұрын
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
@ahmedsultan366 жыл бұрын
One more question. Is there is a way to plot the iterations for this video or similar to it with 3 variables Thanks
@anujagrawal10364 жыл бұрын
why did you used so many square bracket inside fmincon . how many square bracket are needed??
@beoptimistic58534 жыл бұрын
kzbin.info/www/bejne/joGmmHqKbqefqLM 💐💐💐💐💐💐
@bipinkarki96643 жыл бұрын
HOW TO FIND THE OBJECTIVE FUNCTION USING TWO VARIABLES?
@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?
@ns3lover7796 жыл бұрын
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.
@juansebastianhincapiemonte46633 жыл бұрын
You have to install the optimization toolbox
@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.