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

조회 수: 3 (최근 30일)
Karim KARIM
Karim KARIM 2023년 3월 29일
편집: Torsten 2023년 3월 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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by