How to minimize a function when variables do not appear directly?

1 回表示 (過去 30 日間)
Pasquale
Pasquale 2017 年 11 月 3 日
コメント済み: Pasquale 2017 年 11 月 4 日
The code is too complicated, so I resume its structure in equivalent way: I choose a start vector x, for example x=[x1 x2 x3 x4] (for my problem it could have more than 1000 elements), and through separate functions I calculate the vectors a,b,c,d. Each of them depends on the previous one, more or less in this way:
a=f(x);
b=f(a,par1,par2,par3);
c=f(b,x,par1,par2,par3);
d=f(c,par1,par2,par3);
The object function (OF) I want to minimize is very simple, something like OF=d1+d2+d3+d4, but how can I find the vector x that minimizes OF if it does not appear in the function?
  6 件のコメント
Pasquale
Pasquale 2017 年 11 月 3 日
So if the variable x does not appear directly in OF, it is impossible to use fminnunc or similar minimization functions?
Stephen23
Stephen23 2017 年 11 月 4 日
You just need to pass the parameters to the function exactly as Walter Roberson and the MATLAB documentation show:

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 3 日
par1 = ...
par2 = ...
par3 = ...
func = @(x) minimize_this(x, par1, par2, par3)
[best_x, fval, exitflag, output] = gamultiobj(func, number_of_variables);
function cost = minimize_this(x, par1, par2, par3);
a=f(x);
b=f(a,par1,par2,par3);
c=f(b,x,par1,par2,par3);
d=f(c,par1,par2,par3);
OF = a + b + c + d;
cost = OF;
end
"So if the variable x does not appear directly in OF, it is impossible to use fminnunc or similar minimization functions?"
Not appearing directly in OF is not the problem. You cannot use fminunc or similar minimization functions because your OF is a vector and it is meaningless to minimize a vector.

その他の回答 (1 件)

Pasquale
Pasquale 2017 年 11 月 4 日
Thanks for advice, but the problem is a bit different. I need a,b and c only to evaluate d. To make the problem realistic, a is a displacement vector, b are strains, c stresses, and d stress combination, so they can be calculated only one after the other. When I get d, my OF is the sum of the elements of d vector, so it is scalar. For example OF=d1+d2, or OF=d1+d2+d3+d4+d5...+d1000 (vectors x and d have the same length, this depends on the mesh size).
  9 件のコメント
Stephen23
Stephen23 2017 年 11 月 4 日
@Pasquale: you should accept Walter Roberson's answer, because it correctly resolves your question.
Pasquale
Pasquale 2017 年 11 月 4 日
Done

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

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by