Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
Antonio
Antonio am 9 Nov. 2015
Bearbeitet: Walter Roberson am 11 Nov. 2015
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?

Antworten (2)

Walter Roberson
Walter Roberson am 9 Nov. 2015
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 Kommentare
Walter Roberson
Walter Roberson am 10 Nov. 2015
Bearbeitet: Walter Roberson am 11 Nov. 2015
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 am 11 Nov. 2015
Bearbeitet: Walter Roberson am 11 Nov. 2015
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

Melden Sie sich an, um zu kommentieren.


Alan Weiss
Alan Weiss am 9 Nov. 2015
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
  2 Kommentare
Antonio
Antonio am 9 Nov. 2015
As far as I know fmincon function is only for one-variable functions not for multi-variable functions like mine!
Walter Roberson
Walter Roberson am 9 Nov. 2015
"x, lb, and ub can be passed as vectors or matrices; see Matrix Arguments."

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by