how to perform a multi variable optimization on matlab

i have a two variable cost function to minimize,is there specefic type of optimization to do it , i am trying some metaheuristics and when introducing the second variable it shows "not enough input variables" any recommendations please ? thank you

4 comentarios

Please share the mathematical definition of the function you have to minimize, and the code you wrote which gave the error mentioned above.
Anwar
Anwar el 19 de Feb. de 2024
Editada: Walter Roberson el 19 de Feb. de 2024
function [F] = cost function(x, Sv)
x = [0.3 x 0.8];
% Compute dx and ds
dx = diff(x);
ds = -dx;
% Define constants and parameters
dSOC = 0.40;
dSOCdis = 0.40;
dSOCmin = 0.1;
V = 384;
Q = [30, 30, 30, 30, 30, 30, 30, 30, 30];
N = 0.9;
M = 1;
R = [2, 13, 12, 8, 12, 4, 7, 1, 20];
% Ensure Sbk is a row vector
Sv = Sv(:)';
% Compute charging cost C and discharging cost D
C = (V * dx .* Q .* R * (1 / N)) .* ((1 + Sv) / 2) .* Sv.^2;
D = (V * ds .* Q .* R * (1 / M)) .* ((-1 + Sv) / 2) .* Sv.^2;
% Compute total cost J
J = C + D;
% Compute total cost F
F = sum(J);
% constraints
if any(abs(dx) > dSOC) || any(abs(ds) > dSOCdis) || ...
any(abs(dx) < dSOCmin) || any(abs(ds) < dSOCmin) || ...
all(Sv == 0) || all(Sv == 1) || all(Sv == -1) || ...
any(diff(Sv) == 0) || Sv(1) ~= 1 || Sv(end) ~= 1
F = Inf;
end
end
Anwar
Anwar el 19 de Feb. de 2024
for the algorithm used ive tried many metaheuristics and only worked with one variable ,is there a way to make any algorithm work with two variables or there are specefic algorithms for the task
%example
nvars = 23;
fun = @(xSv) costfunction(xSv(1:10), xSv(11:nvars));
[bestxSv, fval] = ga(fun, nvars);

Iniciar sesión para comentar.

Respuestas (1)

There are several different minimizers possible. Everything except fzero() -- fzero() is restricted to one variable.
fun = @(XYZ) YourFunction(XYZ(1), XYZ(2), XYZ(3))

Productos

Versión

R2022b

Preguntada:

el 19 de Feb. de 2024

Comentada:

el 19 de Feb. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by