How to find the minimum of a multivariable vector function in MATLAB?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 29 de Mzo. de 2023
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.
Respuestas (1)
Walter Roberson
el 29 de Mzo. de 2023
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
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!