Optimization Problem With 5 Variables.

4 ビュー (過去 30 日間)
Spottswood
Spottswood 2016 年 10 月 19 日
コメント済み: Spottswood 2016 年 10 月 19 日
Hello I need help with a problem I have to do.
I have to minimize and find the minimal value of
F = (x - 3)^2 + (y - 1)^4 + (u - z)^2 + (u - (2 * w))^2 + (u-6)^2 + 12;
Right now the code i have is
function [Fx] = five_var(f,v)
x = v(1);
y = v(2);
u = v(3);
w = v(4);
z = v(5);
Fx = fminsearch(f, v);
Where I input parameters for v and the function F above for f. However, it is not working and I am not sure why because I am, as far as I can tell, utilizing the same process that the mathworks site recommends. Please help!

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 19 日
F = @(u, w, x, y, z) (x - 3).^2 + (y - 1).^4 + (u - z).^2 + (u - (2 * w)).^2 + (u-6).^2 + 12;
f = @(v) F(v(1), v(2), v(3), v(4), v(5));
initial = randn(1,5) * 100;
fx = fminsearch(f, initial);
However, notice that your variables are mostly separate. You can see by inspection that at the minima, x = 3, y = 1, and you can see that none of the terms are negative so the +12 is a constant shift, so you can reduce this to a search over three variables (u - z).^2 + (u - (2 * w)).^2 + (u-6).^2 . Simple inspection then shows that the minima would be at u = 6, z = u, w = u/2 . This gives an overall solution of u = 6, w = 3, x = 3, y = 1, z = 6
  1 件のコメント
Spottswood
Spottswood 2016 年 10 月 19 日
awesome thanks. I had guessed those as my parameters but could never seem to get it working!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDirect Search についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by