Using fminbnd on a Function with Multiple Outputs

7 ビュー (過去 30 日間)
Thassio Matias
Thassio Matias 2021 年 1 月 10 日
編集済み: Joshua Carmichael 2021 年 12 月 8 日
Hi,
I have a function called errorrms_tal, which is stored in a seperate .m file, and takes three inputs (x, y, z), while producing 3 outputs ( out1, out2, and out3):
[out1, out2, out3] = errorrms_tal(x,y,z);
I would now like to use MatLab's fminbnd to minimized out1 of my function errorrms_tal with respect to the variable x (leaving y and z as just a constants, i.e. not varied as part of the optimisation). Therefore I wanted to do something like the following:
x_optimum = fminbnd(@(x)errorrms_tal(x,y,z),x1,x2);
However, I also would like to know the outputs out2 a out3 of the function errorrms_tal, which is produced when the fminbnd calculate the x_optimum. How can I do it?
Many Thanks

回答 (1 件)

John D'Errico
John D'Errico 2021 年 1 月 10 日
編集済み: John D'Errico 2021 年 1 月 10 日
Just evaluate your function one more time, after the optimization is done when you have the minimal location for x. This last time, you just need to return the other two output parameters.
x_optimum = fminbnd(@(x)errorrms_tal(x,y,z),x1,x2);
[~,out2,out3] = errorrms_tal(x_optimum,y,z);
  2 件のコメント
Thassio Matias
Thassio Matias 2021 年 1 月 10 日
It cold be a good option. However, since the function must be evaluate one more time, it increases the computation time. Is there not another way to do this?
Joshua Carmichael
Joshua Carmichael 2021 年 12 月 8 日
編集済み: Joshua Carmichael 2021 年 12 月 8 日
Without knowing a darn thing about the computational time of your code, in my experience, the computational time required to minimize a function greatly exceeds the time required to call it with the inputs that function requires to output function values. I would assert (again, somewhat ignorantly) that the MVP's solution is probably a stationary one, and I mean that in a good way.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by