How to optimize a multi-variate function based on a constraint?

2 次查看(过去 30 天)
Hi there,
Actually I need to minimize the function: f = sqrt(X^2 + Y^2 + Z^2), based on the constraint: 0.64*X - (9*sqrt(3)/8)*(Y+4)*(0.3*Z+4) + 16 = 0. Indeed, what I want to do is to translate a MAPLE code to MATLAB (please see the attached!) and I really don't know how to do that! Could anybody help me with that please? Can MATLAB do that for me?

回答(2 个)

Walter Roberson
Walter Roberson 2015-11-9
If you have Maple then you can use Maple's CodeGeneration[Matlab](expression) to get the MATLAB equivalent (but the conversion is a bit limited.)
You can also solve() the constraint for X and substitute that in to the function to be minimized, to transform it in to a function of two variables to be minimized without constraint. You can do that the standard way: differentiate it with respect to Y, solve that for Y, to get the Y at which the function has extrema, expressed in terms of Z. Back substitute the Y to get a function of 1 variable to minimize. Differentiate with Z, solve for 0. This will give you a couple of particular Z together with RootOf() a quintic. The particular Z values all lead to division by 0 when you substitute them in to the Y expression, so the Z of interest are the roots of the quintic. Find the roots numerically, substitute each of them in to the expression for Y to get a corresponding set of Y, substitute back in to the function of two variables, and pick the pair that minimizes the function (caution, two of the results will be complex.) That Y, Z in hand, substitute into the expression for X deduced by the constraint.
  3 个评论
Walter Roberson
Walter Roberson 2015-11-10
编辑:Walter Roberson 2015-11-11
To do it in Maple requires the process I described.
>> minimize( sqrt(X^2+Y^2+Z^2)) assuming (.64)*X-(9*sqrt(3)*(1/8))*(Y+4)*((.3)*Z+4)+16 = 0;
infinity
and if you solve() the constraint for any one of the variables and subs() that into the function and attempt to minimize() that, you will get back the function unminimized, indicating that the function is too complex for Maple to handle. You need to proceed using calculus. If it is X that you solved the constraint for you might be able to use minimize() for the final step (finding Z) but if it is Y or Z that you solved the constraint for then if you try to minimize() to find the third variable then Maple will tell you that
Error, (in RootFinding:-Isolate) polynomials to be solved must have numeric coefficients
Perhaps there is a faster route in Maple if you do not mind a numeric approximation, but if you want the function truly minimized and to know it is minimized, then you need the multistage route.
If you do not mind numeric approximation and do not mind lack of proof of the function having been minimized, then you can use MATLAB's fmincon() of f with the nonlinear constraint that you have specified. Or you can do a symbolic solve() of the constraint for X, substitute that into f, rename variables slightly, and fminsearch() the resulting formula in two variables, such as (MATLAB)
f = @(YZ) ((-25+(135/256)*3^(1/2)*YZ(1)*YZ(2)+(225/32)*3^(1/2)*YZ(1)+(135/64)*3^(1/2)*YZ(2)+(225/8)*3^(1/2))^2+YZ(1)^2+YZ(2)^2)^(1/2);
[yz, fmin] = fminsearch(f, rand(1,2));
and then substitute the yz for Y and Z into the formula for X.
Antonio
Antonio 2015-11-11
编辑:Walter Roberson 2015-11-11
Thanks a lot. In maple I simply use Lagrange Multipliers and it solves the whole equation in a blank of an eye! It suggests a few couples of answers and you yourself select the minimum one. Solving this equation is also much easier in excel as it directly gives the amount of X in addition to Y and Z at your first try ... Anyway, isn't it possible to get the value of X at your first try? I mean without substituting Y and Z in the equation, is it possible to get X with Y and Z simultaneously? Also, may I ask how did you get the equation
((-25+(135/256)*3^(1/2)*YZ(1)*YZ(2)+(225/32)*3^(1/2)*YZ(1)+(135/64)*3^(1/2)*YZ(2)+(225/8)*3^(1/2))^2+YZ(1)^2+YZ(2)^2)^(1/2)?!
How did you omit X value? Thanks

请先登录,再进行评论。


Alan Weiss
Alan Weiss 2015-11-9
Perhaps the Optimization Toolbox™ fmincon function can help.
For more details about how to write objective and constraints, see the documentation.
Alan Weiss
MATLAB mathematical toolbox documentation

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by