How to optimize a multi-variate function based on a constraint?
6 ビュー (過去 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?
0 件のコメント
回答 (2 件)
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
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.
Alan Weiss
2015 年 11 月 9 日
Alan Weiss
MATLAB mathematical toolbox documentation
2 件のコメント
Walter Roberson
2015 年 11 月 9 日
"x, lb, and ub can be passed as vectors or matrices; see Matrix Arguments."
参考
カテゴリ
Help Center および File Exchange で Surrogate Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!