It helped me a lot. I am doing a master's degree in HSE and matlab and the resident program, I hope to learn a lot with the support of the page. from: Mozambique
For constrained optimization problems, fmincon solver runs faster compared to genetic algorithm solver. Great tutorial on how to use fmincon solver. Thank you very much Prof.
Gradient based methods are generally much faster than GAs but have the disadvantage of possible local minima and the functions need to be continuous with continuous derivatives. GAs are better for problems where a gradient based method isn't successful.
Thank you for your effort, very useful and well-explained material. Just a small observation: The definition of the lower and upper bounds might be better defined as : lb = 1.0 * ones(4,1); ub = 5.0 * ones(4,1);
Thank you for the tutorial. This actually helped me gain some traction on a linearization problem I have been working on. Super quick questions if I may: 1) Using fmincon, how do you approach the syntax if you have state variables that each have their own bounded and equality constraints? Meaning, in this example, instead of having states x1 -> x5 bounded by 1 and 5, how can you implement constraints on each states (i.e. a < x1
Sir, Thank you so much. You helped me for the take home part of my exam which is due submission tomorrow. I want to learn more about Matlab, from you(FREE, if possible). Would you be interested in helping me?
Thank you for your explaining video. I just want to ask just one question. I have a 4-plies Abaqus model and the objective is to find the minimum deformation for changing plies. How can I assign the objective function and c variables?
If you're trying to optimize the layup sequence of the plies to minimize deformation in an ABAQUS model using MATLAB, here's a general outline of the steps you need to take: Setup ABAQUS Scripting Interface with MATLAB: Before running optimizations, ensure that you can call ABAQUS from MATLAB. This will often involve using the `system` command in MATLAB. For example: cmdStr = 'abaqus job=myModel.inp'; system(cmdStr); Objective Function: Write an objective function in MATLAB that runs your ABAQUS model for a given layup sequence, extracts the deformation result, and then returns this value. function deformation = objectiveFunction(layup) % Write layup to ABAQUS input file writeLayupToInput(layup); % Run ABAQUS simulation cmdStr = 'abaqus job=myModel.inp'; system(cmdStr); % Extract deformation result deformation = extractDeformationFromODB(); % Possibly other post-processing steps... end
Thank you for nice video. Something very small: ones(4) and zeros(4) create 4x4 matrices. For 4-element vectors, ones(4,1) and zeros(4,1) must be used.
Thank you for your effort. I have a few questions for you. 1) I realized that you didn't use set for X variables. You wrote all X variables. However, the problem I need to solve is large-scale. It's impossible for me to define all variables one by one. What should I do? 2) How are fmincon, APM MATLAB toolbox and Python compares to programs such as GAMS, AMPL in solving optimization problems. Which one do you suggest for large-scale nonlinear optimization problems?
Check out Python Gekko for large scale problems. You can also use Gekko in MATLAB. Almost all modeling platforms are similar. It is the solver that makes most of the difference.
Many thanks for the video. How do I modify it to solve linear optimisation without changing the structure of the optimisation problem. I have used it to solve nonlinear system, I have linearized the nonlinear system and I still want to use the fmincon to solve the problem, How do I modify my optimisation? Many thanks.
Linear programming solvers can be much more efficient. You can still use fmincon, just include the linear equations as shown here. Here are some specialized methods for linear programming too: apmonitor.com/pdc/index.php/Main/LinearProgramming
Here is the instruction page: apmonitor.com/che263/index.php/Main/MatlabOptimization with the source code: apmonitor.com/che263/index.php/Main/MatlabOptimization?action=sourceblock&num=2
Hi there, firstly thank you so much for this tut. so I had a simple question. say suppose my objective function contains x(1),x(2) and x(3). how do I limit the bounds of my x(3) between 1 to 20 . thanks
Dear Professor, If the constraintes are a system of differential equations : dx/dt = Ax(t) + bu(t) Where: A is a n*n matrix b is a n-vector u(t) is a command (control) How we can do it ? Thank you
Here is more information on state space models: apmonitor.com/pdc/index.php/Main/StateSpaceModel and control development with state space: apmonitor.com/do
I have a question. I have a set of differential equations. I have an objective function which is a combination of these differential equations. I should minimize the objective function (along with ode solution) with the help of parameters of differential equations where the parameters are subjected to certain bounds. I have no experimental data as well. Can you please help me to solve this. Thank you in advance!
So I Have a hydrolic model that I made and I struggle to do the optimization to 4 parametres in order to have the least loss, and nothing. I saw many tutorials but all of them are for simple functions and I can not find in my case what to do.
great video!! I have a question. I have to do portfolio optimization by minimizing the mean absolute deviation. I have calculated the rate of returns by using real data. how can I continue?
Here is some code for nonlinear MPC in MATLAB: apmonitor.com/do/index.php/Main/NonlinearControl Using fmincon would be much less efficient because you would need to use a shooting (sequential) method.
Thanks a lot prof. I have a question regarding to my assignment( Genetic Algorithm Optimization by using Matlab). My equation is (A +U)n = A + n*A^n-1*U + (𝑛(𝑛−1)/2!)*A^n-2*U^2 + (𝑛(𝑛−1)(𝑛−2) /3!)*A^n-3*U^3… + U*n =1 Where, A = availability of one-unit element in a certain time U = unavailability of one-unit element in a certain time The availability of a system can be expressed in equation: (A + U) n =1 if I wanna do for 2-out-6 system, means 2 sub-system is available to run the whole system if another 4 sub-system failed. i will got As = 1 - (6AU5 + U6). So how can I put this equation for finding fitness function and iteration in Matlab? Thanks a lot if you could help me out of this question.
This video is about a gradient based optimization approach. I recommend that you take a look at the optimization course and the book material in chapter 6. apmonitor.com/me575/index.php/Main/BookChapters
This is a great video, but I'm getting an error that I don't understand. When I finish writing both files and I run them, it works perfectly. But as soon as I pressed save, and then I run it again, I'm getting this error: Not enough input arguments. Error in nlcon (line 2) c = 25-x(1)*x(2)*x(3)*x(4); I would be so thankful sir if you could help me with this!
Good evening, i have to obtain the power Pp0, Pp1, Pp2 and Pp3 for a gain optimization. The equations are the following: G1=exp(-alpha_s1*L+a1*Pp0+b1*Pp1+c1*Pp2+d1*Pp3); G2=exp(-alpha_s2*L+a2*Pp0+b2*Pp1+c2*Pp2+d2*Pp3); G3=exp(-alpha_s3*L+a3*Pp0+b3*Pp1+c3*Pp2+d3*Pp3); G1=exp(-alpha_s4*L+a4*Pp0+b4*Pp1+c4*Pp2+d4*Pp3); a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4,L and alpha_s1, alpha_s2,alpha_s3,alpha_s4 are constants. How can i implement it?
It sounds like you need to solve a nonlinear regression problem. Do you have data for G1 through G4? Here is a tutorial for a similar problem in Python: apmonitor.com/me575/index.php/Main/NonlinearRegression
+panaluu, x0 is the initial guess. Sometimes the problem statement specifies the initial guess (like this time) or you just need to insert an educated guess.
Congratulations for the video! May you help me? I have the following problem: I need to implement some nonlinear constraints, but they are another functions, with the same enter variables. How can I write the code in this case?
The fmincon solver works with any number or form of nonlinear constraints. You can try another platform (APMonitor Matlab interface). If fmincon doesn't work.
Thanks for your video. How do you set up your nonlinear constraints if they are in the form of sets of diferential equations, as in state space format? I know it's easy using APM, just curious to see how it's done in MATLAB. I believe that would render the problem from a pure optimization problem into an optimal control problem, am I correct? Thanks
+Edmond A, you can add the differential equation solution in the objective function subroutine with a shooting (sequential) method. Another method that is more difficult to configure but often much faster. It is a simultaneous method by orthogonal collocation on finite elements. The differential equation is discretized into a set of algebraic constraints and added to the optimization problem. APMonitor uses both approaches as well as a hybrid technique. More info on orthogonal collocation in MATLAB is here: apmonitor.com/do/index.php/Main/OrthogonalCollocation
Thank you for yor tutorial video, I got an error message, that fmincon is undefined at line 12 and I don't know the solution. is there anyone who can help me?
Thank you soooo much for this helpful video.I want to know how to add linear equality constraint with in the same function? i tried to make another function of equality constraint but its not working.if you can kindly help
You just need to load values into the A and b terms (inequalities) or else the Aeq and beq terms (equalities) such as shown here: x0 = [0.5,0]; A = [1,2]; b = 1; Aeq = [2,1]; beq = 1; x = fmincon(fun,x0,A,b,Aeq,beq) www.mathworks.com/help/optim/ug/fmincon.html
Thanks for the video. I do have a question I wanted to ask. Since the objective function in the video above is not convex(i think), and the Ceq is also not convex (not affine), it means the solution it gave is local minimum. Suppose the inputs are all convex instead, does this guarantee the solution will be global minimum?
That is correct. For this specific example, you can get a different solution based on the initial variable guess. For convex problems, the optimal local solution is also the global solution as long as the solver verifies that the KKT conditions are satisfied (reports successful solution): apmonitor.com/me575/index.php/Main/KuhnTucker
It is an element-wise operator to do the square of each element in the array. Here is additional help on matrix and element-wise operators: www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
There is no way to write the "not equal to" constraint with this solver. You could use Python Gekko and use the Mixed Integer capabilities to write that constraint.
+Diogo Oliveira, the source code for this tutorial and another are at: apmonitor.com/che263/index.php/Main/MatlabOptimization. I'd recommend the APM Matlab toolbox for large optimization problems such as 10,000+ variables.
Hello, Many thanks for that excellent presentation, But I have a question: What's about if I want to optimize two equations or three simultaneously, For example what I am working on it nowadays, I'd like to optimize J = (xy - zt)^2 with respect to the for variables x, y , z and ... which means optimizing the difference between their products, but at the same time, I would like to optimize the J1 = xy and J2 = zt. It means to optimize the difference of optimized multiplications. Is that possible ? which algorithm is usually used for that? Thank you so much in advance.
Multiple equations aren't a problem but you typically need to have just one objective function. If you have multiple objectives that don't have a mathematical trade-off then you need to form a Pareto front. The Pareto front will help you decide what optimal combination of objectives is acceptable. See chapter 5: apmonitor.com/me575/index.php/Main/BookChapters
Thank you for your tutorials! I tried to find right article or video, but failed. Well, i need to fined a minimum of function with 40+ variables (it's functional for nonlinear MPC). The function is nonlinear and has a lot of local minima. Could you advice me something please? I already tried a fmincon, ga in matlab. It gives some results but not what i expect. p.s. I apologize for the mistakes, English is not my native language
+Au6oJluT, here are some files for Nonlinear MPC: apmonitor.com/do/index.php/Main/NonlinearControl. If your problem has multiple local minima, you may need to try a multi-start method. One way to have an intelligent multi-start method is to use simulated annealing or a genetic algorithm. More information on simulated annealing is here: apmonitor.com/me575/index.php/Main/SimAnnealHW
Yes, you can have multiple inequality constraints and no equality constraints. If you have no equality constraints then you return ceq = []. If you have multiple inequality constraints then you return c = [c1,c2] where c1 and c2 are your inequality constraints.
okay, thank-you for your speedy reply, and for your helpful video. Just to confirm, if I had followed your video example, the only difference being: 1) no equality constraint 2) lower bound is negative number The final objective should be correct?
@@apm Sir i am a student i am working on matlab on both linear and non linear programing .i watch a lot of your videos that are very helpful. Can you have a solved exampel of any heuristic and meta _ heuristic in matlab .or in any of your sylabeus that you teach if done so kindly provide the link . Thanks
thank you so much for this such an informative video. I what to learn how to numerically minimize free energy functional provided by Chan-Hilliard. I want to learn it since this is very much required for my Ph.D. work and I am ready to pay the cost. If you could help me I am very thankful to you.
Sorry, I can't help with specific projects. Here is some information that may help: cmsr.rutgers.edu/images/people/lebowitz_joel/publications/carlen_carvalho_esposito_marra_518latestversion.pdf and apmonitor.com/wiki/index.php/Apps/GibbsFreeEnergy I also maintain the Gekko Optimization Suite that may help with your project: apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization If you prefer to use Matlab, here is an interface: apmonitor.com/che263/index.php/Main/MatlabCallsPython
sir, i have linear equation A=a0+a1*B+a2*C+a3*D+a4*E , the coeficients values i know and i have (B,C,D,E) 5 values for each variable, i want to put A is constant then i want to find the optimum values of B,C,D,E how i can do please answer me
Hi, how can I read values for constants or parameters from Matlab, I want to use APM as an NLP solver in Matlab script, so I need pass parameter from Matlab to APM?
I'd recommend the function apm_meas(server,app,name,value). This inserts a measurement into the model for an FV or MV with feedback status on (FSTATUS=1).
Sorry, I don't have any material on linking IPOPT to MATLAB directly. MATLAB would need to provide at least the first derivatives and possibly the 2nd derivatives as well. A modeling language such as Pyomo, APMonitor, GAMS, AMPL, or others are generally used to simplify the process of providing derivatives and other information that the solvers need.
You need to return the constraints as a vector from that function to include multiple nonlinear constraints. Also check out APM Matlab for another option if your problem is large-scale or difficult to solve. apmonitor.com/wiki/index.php/Main/MATLAB
shashank shekar mupparam, this may be a scheduling optimization problem with mixed integer elements. fmincon won't be able to handle discrete systems. You may want to look at an MINLP or MILP solver such as APOPT.
I have a nonlinear optimization programming course that is available at apmonitor.com/me575 Please see the PDF textbook and the many lecture videos that are available.
This is a beginner guide with a very basic example. There are better videos for those who need some of the more advanced features of the solver. For more capable solvers see apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization
I have a problem with a system developed in Simulink. Is a militar tank with six road whels, 8 DOF. I want to optimize with Fmincon the bounce, but I don't understand how to interconnect Simulink with fmincon. Can you help me? Do you have any material on this? Thank you.
It sounds like your vehicle model is in Simulink. Here is some information on converting your model to MATLAB (solve with ode15s or ode23). apmonitor.com/che263/index.php/Main/MatlabDynamicSim Once it is converted to a MATLAB form, it can be optimized with fmincon. You may also want to look at the APMonitor MATLAB toolbox, specifically designed to optimize systems of differential and algebraic equations.
Please ask your questions here, on public forums such as Stack Overflow, or on Mathworks support site. Unfortunately I can't answer all of the questions that are given to me each week by users who need specific help with their application. I also have additional tutorials at the course website apmonitor.com/che263
It helped me a lot. I am doing a master's degree in HSE and matlab and the resident program, I hope to learn a lot with the support of the page.
from: Mozambique
For constrained optimization problems, fmincon solver runs faster compared to genetic algorithm solver. Great tutorial on how to use fmincon solver. Thank you very much Prof.
Agree. fmincon solver is better than genetic algorithm solver.
Solving Optimization Problems Really? Thanks for this suggestion. I will try both solvers to see the difference.
Gradient based methods are generally much faster than GAs but have the disadvantage of possible local minima and the functions need to be continuous with continuous derivatives. GAs are better for problems where a gradient based method isn't successful.
Thank you. This was really helpful. I see why people use MATLAB over Python now; it's easier AND the functions are more powerful.
Instablaster.
Proffesor John D. Hedengren, Thank you very much. All your videos are very heplfu to me.
Thank you for your effort, very useful and well-explained material. Just a small observation: The definition of the lower and upper bounds might be better defined as :
lb = 1.0 * ones(4,1);
ub = 5.0 * ones(4,1);
Thanks for the suggestion!
Thank you for the tutorial. This actually helped me gain some traction on a linearization problem I have been working on. Super quick questions if I may:
1) Using fmincon, how do you approach the syntax if you have state variables that each have their own bounded and equality constraints? Meaning, in this example, instead of having states x1 -> x5 bounded by 1 and 5, how can you implement constraints on each states
(i.e. a < x1
Use the lb and ub (lower and upper bounds) as input arguments to fmincon.
Set your bounds like this: lower bound = [ 1 2 1 0] and upper bound = [5 7 9 3] ; So, x1 = (1 to 5), x2 = (2 to 7), x3 = (1 to 9), and x4 = (0 to 3)
This video explains it better than my tutor... amazing! Thank your for your work
This is amazing! I was struggling to find the right tutorial. Thank you.
Sir, Thank you so much. You helped me for the take home part of my exam which is due submission tomorrow. I want to learn more about Matlab, from you(FREE, if possible). Would you be interested in helping me?
sure, there is course content available at apmonitor.com/che263
Helped me in understanding something I'm working on...You sound like Jim Halpert from 'The Office'...Haha
Thanks! That's a first! I've had a few say that I sound like Matthew McConaughey. I'll take either one as a complement.
Thank you for your explaining video. I just want to ask just one question. I have a 4-plies Abaqus model and the objective is to find the minimum deformation for changing plies. How can I assign the objective function and c variables?
If you're trying to optimize the layup sequence of the plies to minimize deformation in an ABAQUS model using MATLAB, here's a general outline of the steps you need to take:
Setup ABAQUS Scripting Interface with MATLAB: Before running optimizations, ensure that you can call ABAQUS from MATLAB. This will often involve using the `system` command in MATLAB. For example:
cmdStr = 'abaqus job=myModel.inp';
system(cmdStr);
Objective Function: Write an objective function in MATLAB that runs your ABAQUS model for a given layup sequence, extracts the deformation result, and then returns this value.
function deformation = objectiveFunction(layup)
% Write layup to ABAQUS input file
writeLayupToInput(layup);
% Run ABAQUS simulation
cmdStr = 'abaqus job=myModel.inp';
system(cmdStr);
% Extract deformation result
deformation = extractDeformationFromODB();
% Possibly other post-processing steps...
end
Thank you for nice video. Something very small: ones(4) and zeros(4) create 4x4 matrices. For 4-element vectors, ones(4,1) and zeros(4,1) must be used.
Thanks for the tip.
Great video! Very well explained....thanks a lot for the efforts!
Thank you very much. This is the great help for the beginners like me...
Thank you for your effort. I have a few questions for you.
1) I realized that you didn't use set for X variables. You wrote all X variables. However, the problem I need to solve is large-scale. It's impossible for me to define all variables one by one. What should I do?
2) How are fmincon, APM MATLAB toolbox and Python compares to programs such as GAMS, AMPL in solving optimization problems. Which one do you suggest for large-scale nonlinear optimization problems?
Check out Python Gekko for large scale problems. You can also use Gekko in MATLAB. Almost all modeling platforms are similar. It is the solver that makes most of the difference.
this video is very helpful, thanks so much
Many thanks for the video. How do I modify it to solve linear optimisation without changing the structure of the optimisation problem. I have used it to solve nonlinear system, I have linearized the nonlinear system and I still want to use the fmincon to solve the problem, How do I modify my optimisation? Many thanks.
Linear programming solvers can be much more efficient. You can still use fmincon, just include the linear equations as shown here. Here are some specialized methods for linear programming too: apmonitor.com/pdc/index.php/Main/LinearProgramming
Why do you ignore the warning?
Is it right the way you define the lower and upper bounds?
Here is the instruction page: apmonitor.com/che263/index.php/Main/MatlabOptimization with the source code: apmonitor.com/che263/index.php/Main/MatlabOptimization?action=sourceblock&num=2
Hi there, firstly thank you so much for this tut. so I had a simple question. say suppose my objective function contains x(1),x(2) and x(3). how do I limit the bounds of my x(3) between 1 to 20 . thanks
See the lb and ub as lower bound and upper bound for each variable: apmonitor.com/che263/index.php/Main/MatlabOptimization
@@apm thanks for your reply. I had just got it while playing around with the values from another tutorial.
Dear Professor,
If the constraintes are a system of differential equations :
dx/dt = Ax(t) + bu(t)
Where:
A is a n*n matrix
b is a n-vector
u(t) is a command (control)
How we can do it ?
Thank you
Here is more information on state space models: apmonitor.com/pdc/index.php/Main/StateSpaceModel and control development with state space: apmonitor.com/do
I have a question. I have a set of differential equations. I have an objective function which is a combination of these differential equations. I should minimize the objective function (along with ode solution) with the help of parameters of differential equations where the parameters are subjected to certain bounds. I have no experimental data as well. Can you please help me to solve this. Thank you in advance!
Here is something that may help: apmonitor.com/do/index.php/Main/DynamicEstimation
@@apm Thank you!
Thank you very much for your tutorials. I have one question. Is there a problem if flag=-2?
Yes, there is a problem. The solver is reporting that no feasible point was found.
I need to minimize x2,x4,x6 using GA toolbox matlab
For the function
f(x)=(x1*x2)+(x3*x4)+(x5*x6)
Subject to constraints
0≤x2≤100
0≤x4≤ 20
0≤x6≤ 10
So I Have a hydrolic model that I made and I struggle to do the optimization to 4 parametres in order to have the least loss, and nothing. I saw many tutorials but all of them are for simple functions and I can not find in my case what to do.
Try Python gekko such a problem 9 apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization
great video!! I have a question. I have to do portfolio optimization by minimizing the mean absolute deviation. I have calculated the rate of returns by using real data. how can I continue?
Try Python Gekko for portfolio optimization: th-cam.com/video/bXAkr7MPf4w/w-d-xo.html
Its a great video! Thank you so much. Can I use the fmincon to solve a nonlinear MPC problem. If so, can you guide me a bit
Here is some code for nonlinear MPC in MATLAB: apmonitor.com/do/index.php/Main/NonlinearControl Using fmincon would be much less efficient because you would need to use a shooting (sequential) method.
What if I want the 40 in nolcon to be a variable and call fmincon many times?
Thanks for the video btw. Very helpfull!
Yes, you can make any of the constants into a variable. You'll just need to include it as a variable in the optimization problem, similar to x1-x4.
Wonderful
Can you please optimize the water filling algorithm using fmincon?
Here is something that may help: apmonitor.com/pdc/index.php/Main/LevelControl
Thanks a lot prof. I have a question regarding to my assignment( Genetic Algorithm Optimization by using Matlab). My equation is (A +U)n = A + n*A^n-1*U + (𝑛(𝑛−1)/2!)*A^n-2*U^2 + (𝑛(𝑛−1)(𝑛−2) /3!)*A^n-3*U^3… + U*n =1
Where,
A = availability of one-unit element in a certain time
U = unavailability of one-unit element in a certain time
The availability of a system can be expressed in equation:
(A + U) n =1
if I wanna do for 2-out-6 system, means 2 sub-system is available to run the whole system if another 4 sub-system failed.
i will got As = 1 - (6AU5 + U6).
So how can I put this equation for finding fitness function and iteration in Matlab?
Thanks a lot if you could help me out of this question.
This video is about a gradient based optimization approach. I recommend that you take a look at the optimization course and the book material in chapter 6. apmonitor.com/me575/index.php/Main/BookChapters
Thank a lot. It really helped me to solve my problem
This is a great video, but I'm getting an error that I don't understand. When I finish writing both files and I run them, it works perfectly. But as soon as I pressed save, and then I run it again, I'm getting this error:
Not enough input arguments.
Error in nlcon (line 2)
c = 25-x(1)*x(2)*x(3)*x(4);
I would be so thankful sir if you could help me with this!
Try 'clear all' at the top of your script.
how can i make the opt solution to give me x1 and x2 as multiples of 10 ?
fmincon can't solve mixed integer problems. Use APM Matlab or Gekko for MINLP options.
Good evening, i have to obtain the power Pp0, Pp1, Pp2 and Pp3 for a gain optimization. The equations are the following:
G1=exp(-alpha_s1*L+a1*Pp0+b1*Pp1+c1*Pp2+d1*Pp3);
G2=exp(-alpha_s2*L+a2*Pp0+b2*Pp1+c2*Pp2+d2*Pp3);
G3=exp(-alpha_s3*L+a3*Pp0+b3*Pp1+c3*Pp2+d3*Pp3);
G1=exp(-alpha_s4*L+a4*Pp0+b4*Pp1+c4*Pp2+d4*Pp3);
a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4,L and alpha_s1, alpha_s2,alpha_s3,alpha_s4 are constants.
How can i implement it?
It sounds like you need to solve a nonlinear regression problem. Do you have data for G1 through G4? Here is a tutorial for a similar problem in Python: apmonitor.com/me575/index.php/Main/NonlinearRegression
G1=G2=G3=G4=G_target, i can choose an arbitrary value. How becomes this in Matlab?
I don't understand the Python, could you help me with matlab?
Shouldn't lb and ub be vectors and not arrays?
A 1D array is also called a vector. Thanks for that clarification.
Thank you sir! This tutorial helped a lot!
th-cam.com/video/XPCgGT9BlrQ/w-d-xo.html 👍💐
Where do I find info finding x(0)? Maybe a dumb question but I don't see where you got that?
+panaluu, x0 is the initial guess. Sometimes the problem statement specifies the initial guess (like this time) or you just need to insert an educated guess.
Congratulations for the video!
May you help me?
I have the following problem: I need to implement some nonlinear constraints, but they are another functions, with the same enter variables. How can I write the code in this case?
The fmincon solver works with any number or form of nonlinear constraints. You can try another platform (APMonitor Matlab interface). If fmincon doesn't work.
Thanks for your video.
How do you set up your nonlinear constraints if they are in the form of sets of diferential equations, as in state space format?
I know it's easy using APM, just curious to see how it's done in MATLAB.
I believe that would render the problem from a pure optimization problem into an optimal control problem, am I correct?
Thanks
+Edmond A, you can add the differential equation solution in the objective function subroutine with a shooting (sequential) method. Another method that is more difficult to configure but often much faster. It is a simultaneous method by orthogonal collocation on finite elements. The differential equation is discretized into a set of algebraic constraints and added to the optimization problem. APMonitor uses both approaches as well as a hybrid technique. More info on orthogonal collocation in MATLAB is here: apmonitor.com/do/index.php/Main/OrthogonalCollocation
Thank you for yor tutorial video, I got an error message, that fmincon is undefined at line 12 and I don't know the solution. is there anyone who can help me?
You may not have the optimization toolbox. Here are alternatives: apmonitor.com/che263/index.php/Main/MatlabOptimization
Thank you soooo much for this helpful video.I want to know how to add linear equality constraint with in the same function? i tried to make another function of equality constraint but its not working.if you can kindly help
You just need to load values into the A and b terms (inequalities) or else the Aeq and beq terms (equalities) such as shown here:
x0 = [0.5,0];
A = [1,2];
b = 1;
Aeq = [2,1];
beq = 1;
x = fmincon(fun,x0,A,b,Aeq,beq)
www.mathworks.com/help/optim/ug/fmincon.html
Thanks. It was very helpful.
why did you use "@(x)" in the objetive ?
It is an anonymous function in Matlab. Check out the course apmonitor.github.io/begin_matlab in the functions module.
Thanks for the video. I do have a question I wanted to ask.
Since the objective function in the video above is not convex(i think), and the Ceq is also not convex (not affine), it means the solution it gave is local minimum.
Suppose the inputs are all convex instead, does this guarantee the solution will be global minimum?
That is correct. For this specific example, you can get a different solution based on the initial variable guess. For convex problems, the optimal local solution is also the global solution as long as the solver verifies that the KKT conditions are satisfied (reports successful solution): apmonitor.com/me575/index.php/Main/KuhnTucker
Brilliant. Subscribed.
Thanks Geoff!
why do add the dott at 4.39?
It is an element-wise operator to do the square of each element in the array. Here is additional help on matrix and element-wise operators: www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
Hi , How to write constraints like
x1 != 0
0
There is no way to write the "not equal to" constraint with this solver. You could use Python Gekko and use the Mixed Integer capabilities to write that constraint.
Thank you for your tutorials/videos. I need to find a minimum of function with 250 variables for mass balance. Could you advice me something please?
+Diogo Oliveira, the source code for this tutorial and another are at: apmonitor.com/che263/index.php/Main/MatlabOptimization. I'd recommend the APM Matlab toolbox for large optimization problems such as 10,000+ variables.
Hello, Many thanks for that excellent presentation, But I have a question: What's about if I want to optimize two equations or three simultaneously, For example what I am working on it nowadays, I'd like to optimize J = (xy - zt)^2 with respect to the for variables x, y , z and ... which means optimizing the difference between their products, but at the same time, I would like to optimize the J1 = xy and J2 = zt. It means to optimize the difference of optimized multiplications. Is that possible ? which algorithm is usually used for that? Thank you so much in advance.
Multiple equations aren't a problem but you typically need to have just one objective function. If you have multiple objectives that don't have a mathematical trade-off then you need to form a Pareto front. The Pareto front will help you decide what optimal combination of objectives is acceptable. See chapter 5: apmonitor.com/me575/index.php/Main/BookChapters
I need bi-level programming please
See Bard, Practical Bilevel Optimization: Algorithms And Applications, Springer, 1998.
King 👑 👑 👑
Thank you for your tutorials! I tried to find right article or video, but failed. Well, i need to fined a minimum of function with 40+ variables (it's functional for nonlinear MPC). The function is nonlinear and has a lot of local minima. Could you advice me something please? I already tried a fmincon, ga in matlab. It gives some results but not what i expect.
p.s. I apologize for the mistakes, English is not my native language
+Au6oJluT, here are some files for Nonlinear MPC: apmonitor.com/do/index.php/Main/NonlinearControl. If your problem has multiple local minima, you may need to try a multi-start method. One way to have an intelligent multi-start method is to use simulated annealing or a genetic algorithm. More information on simulated annealing is here: apmonitor.com/me575/index.php/Main/SimAnnealHW
Thanks for the video. I have a quick question, if you don't mind.
For the ceq does the matlab fmincon assume that it is equal to 0?
For your c you had
Yes, you can have multiple inequality constraints and no equality constraints. If you have no equality constraints then you return ceq = []. If you have multiple inequality constraints then you return c = [c1,c2] where c1 and c2 are your inequality constraints.
okay, thank-you for your speedy reply, and for your helpful video.
Just to confirm, if I had followed your video example, the only difference being:
1) no equality constraint
2) lower bound is negative number
The final objective should be correct?
Or I have to go back and defined c as [c1,c2] in the function that is allowed and then configure ceq as [] (or zero?) if allowed syntax.
Yes, that is correct.
@@apm Sir i am a student i am working on matlab on both linear and non linear programing .i watch a lot of your videos that are very helpful.
Can you have a solved exampel of any heuristic and meta _ heuristic in matlab .or in any of your sylabeus that you teach if done so kindly provide the link . Thanks
thank you so much for this such an informative video. I what to learn how to numerically minimize free energy functional provided by Chan-Hilliard. I want to learn it since this is very much required for my Ph.D. work and I am ready to pay the cost. If you could help me I am very thankful to you.
Sorry, I can't help with specific projects. Here is some information that may help: cmsr.rutgers.edu/images/people/lebowitz_joel/publications/carlen_carvalho_esposito_marra_518latestversion.pdf and apmonitor.com/wiki/index.php/Apps/GibbsFreeEnergy I also maintain the Gekko Optimization Suite that may help with your project: apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization If you prefer to use Matlab, here is an interface: apmonitor.com/che263/index.php/Main/MatlabCallsPython
I can't use your code, because it's false. It only advent hear:
"objective
objective =
@(x)x(1)*x(4)*(x(1)+x(2)+x(3))+x(3)"
Try using the code at apmonitor.com/che263/index.php/Main/MatlabOptimization
sir, i have linear equation A=a0+a1*B+a2*C+a3*D+a4*E , the coeficients values i know and i have (B,C,D,E) 5 values for each variable, i want to put A is constant then i want to find the optimum values of B,C,D,E how i can do please answer me
I recommend that you use the polyfit function. apmonitor.com/che263/index.php/Main/MatlabDataRegression
sir , i ask about optimization with 5 variables, please can help me
Thank you for sharing! :)
Thank you very much
Hi, how can I read values for constants or parameters from Matlab, I want to use APM as an NLP solver in Matlab script, so I need pass parameter from Matlab to APM?
I'd recommend the function apm_meas(server,app,name,value). This inserts a measurement into the model for an FV or MV with feedback status on (FSTATUS=1).
Hi, do you have example that directely call ipopt in matlab without linking APM?
Sorry, I don't have any material on linking IPOPT to MATLAB directly. MATLAB would need to provide at least the first derivatives and possibly the 2nd derivatives as well. A modeling language such as Pyomo, APMonitor, GAMS, AMPL, or others are generally used to simplify the process of providing derivatives and other information that the solvers need.
Thank you.
how to put multiple nonlinear constraints ?
You need to return the constraints as a vector from that function to include multiple nonlinear constraints. Also check out APM Matlab for another option if your problem is large-scale or difficult to solve. apmonitor.com/wiki/index.php/Main/MATLAB
nice
thanku for ur help i have strucked to relate this with relay coordination in power system coordination can u help me sir
shashank shekar mupparam, this may be a scheduling optimization problem with mixed integer elements. fmincon won't be able to handle discrete systems. You may want to look at an MINLP or MILP solver such as APOPT.
Yeah I want to look for it my function is hyperbolic of order 2 so non linear function minimization I need kindly suggest me with some lectures
I have a nonlinear optimization programming course that is available at apmonitor.com/me575 Please see the PDF textbook and the many lecture videos that are available.
i need matlab coding with sub programs for crossover,mutation and selection
so plzzz help with these 3
I don't have any specific code for a GA but there is information on how to program it here: apmonitor.com/me575/index.php/Main/GeneticAlgorithms
Thanks
thank you for these vidoes,and i'need airship model in simulink matlab can you make video for help
+ayoub madrid, sorry I don't have an airship model.
+ayoub madrid, you may want to look on Mathworks File Exchange site.
thanks
Sir please solve this non linear optimization problem by PSO algorithm : Max.Z = 10 x1 + 4 x2 - 2 x1^2 - 3 x2^2
subject to 2 x1 + x2 0
Sorry, I can't help with the many requests for individual support, especially those that may be related to homework.
Thank you :)
just after watching a vedio with more detailed explanations.. didn't find this helpful
This is a beginner guide with a very basic example. There are better videos for those who need some of the more advanced features of the solver. For more capable solvers see apmonitor.com/wiki/index.php/Main/GekkoPythonOptimization
I STILL STRUGGLE XD
I have a problem with a system developed in Simulink. Is a militar tank with six road whels, 8 DOF. I want to optimize with Fmincon the bounce, but I don't understand how to interconnect Simulink with fmincon. Can you help me? Do you have any material on this?
Thank you.
It sounds like your vehicle model is in Simulink. Here is some information on converting your model to MATLAB (solve with ode15s or ode23). apmonitor.com/che263/index.php/Main/MatlabDynamicSim Once it is converted to a MATLAB form, it can be optimized with fmincon. You may also want to look at the APMonitor MATLAB toolbox, specifically designed to optimize systems of differential and algebraic equations.
3:29
I have your email
Please ask your questions here, on public forums such as Stack Overflow, or on Mathworks support site. Unfortunately I can't answer all of the questions that are given to me each week by users who need specific help with their application. I also have additional tutorials at the course website apmonitor.com/che263