How to find the minimum of a multivariable vector function in MATLAB?

6 次查看(过去 30 天)
if we have a vector function where all elements of it are multivariable functions such that f= @(x)[x(1)^3-x(2)^2;3*exp(x(1))-x(2)^5+1]; how to find the minimum of any function from f in matlab
  3 个评论
Walter Roberson
Walter Roberson 2023-3-29
My interpretation is that they would like to be able to indicate an index of a function to minimize -- so for example to minimize the second function in f.
Torsten
Torsten 2023-3-30
编辑:Torsten 2023-3-30
According to the wording of the question, you are right.
But it gives -Inf for both f1 and f2 while f1^2+f2^2 has a finite solution.
But maybe the f above was only an example.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2023-3-29
If you have an anonymous function that creates a vector of values, and you want to optimize one of the elements, then you have a few possibilities:
  • you can create a wrapper function that executes the function handle and then indexes to select the one result you want. This would involve executing all of the members of the function and then ignoring the ones you do not want
  • in some cases, you can create a symbolic variable, evaluate the function at the variable, extract the symbolic output you need, and use matlabFunction() to turn the result back into an anonymous function that does only that part. This has the advantage that if the anonymous function has any "bound" variables, that the new function will use the correct value that was bound into the anonymous function. However, you might perhaps not have the symbolic toolbox, or the function might happen to involve constructs that cannot be executed symbolically
  • You can use func2str to extract a character representation of the anonymous function, and use text operations to select out the portion you want, and then use str2func to create a new function. This does not need the symbolic toolbox, and it is able to use all functions that can be used numerically. However, this approach is not (without further effort) able to use any variables that were "bound" into the anonymous function

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by