Filter löschen
Filter löschen

fmincon con input handle function

3 Ansichten (letzte 30 Tage)
Hynod
Hynod am 9 Sep. 2023
Bearbeitet: Gowtham am 27 Sep. 2023
Buongiorno, ho un dubbio sull'utilizzo della routine fmincon. Ho letto la documentazione, e la call prevede una funzione esplicita in un tot di variabili e dei coefficenti che vanno a determinare i vincoli di uguaglianza e disuguaglianza lineare. Volevo chiedere se invece di una funzione esplicita, fosse possibile passare in input una handle function, come ad esempio un integratore numerico (che ad esempio fa variare le condizioni iniziali per minimizzare l output di integrazione). Nella documentazione l' unico esempio che riporta la chiamata di una handle function, prevede comunque una funzione esplicita all'interno della handle.

Antworten (1)

Gowtham
Gowtham am 20 Sep. 2023
Bearbeitet: Gowtham am 27 Sep. 2023
Hello Hynod,
I understand that you want to pass handle as an input for fmincon function. To achieve this, we can use the integral function which is a numerical integrator function.
For a sample demonstration of this process, kindly refer to the following steps:
% Initial point
x0 = [1 2];
% Call fmincon to minimize the objective function.
[x, fval] = fmincon(@myObjective, x0);
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
disp(x);
1.0000 1.0000
disp(fval);
-8.7939e-24
function f = f(x)
% This function defines the function f(x) to be integrated.
f = x.^2 - 2*x + 1;
end
function objective = myObjective(x)
% This function returns the objective function value, which is the integral of f(x).
objective = integral(@f, x(1), x(2));
end
Kindly refer to the following MATLAB documentation for further understanding on fmincon and integral
Hope this helps in resolving the issue you were facing.
Regards,
Gowtham

Community Treasure Hunt

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

Start Hunting!