How to find maximum of a multivariable function using max()
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
enter
am 29 Mär. 2020
Kommentiert: Ameer Hamza
am 30 Mär. 2020
How to find maximum of a multivariable function using max(). Let's denote z = (y+cos(y))/(x^2) for x,y belonging to [1,15].
Akzeptierte Antwort
Ameer Hamza
am 29 Mär. 2020
Bearbeitet: Ameer Hamza
am 30 Mär. 2020
You can use fmincon function to find maximum value
z = @(x,y) (y+cos(y))./(x.^2);
sol = fmincon(@(x) -z(x(1),x(2)), 10*rand(2,1), [], [], [], [], [1;1], [15;15]);
x_sol = sol(1);
y_sol = sol(2);
4 Kommentare
Ameer Hamza
am 30 Mär. 2020
Michal, this is the limitation of the numerical optimization algorithm. They are sensitive to the initial guess. I found that for your objective function, 'interior-point' algorithm gives consistent results.
z = @(x,y) (y+cos(y))./(x.^2);
opts = optimoptions('fmincon', 'Algorithm', 'interior-point');
sol = fmincon(@(x) -z(x(1),x(2)), rand(1,2), [], [], [], [], [1;1], [15;15], [], opts);
x_sol = sol(1);
y_sol = sol(2);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!