optimization of resources for organization with limited resources

Solve this in matlab for i=5; V=[10 9 12 8 9]; d=[4 8 6 7 5]; B=5; c=0.05

6 comentarios

What have you tried yet?
Use "fmincon".
but fmincon is use to solve linear program but my problem is nonlinear in nature.
"but fmincon is use to solve linear program ..."
Wrong. The description of fmincon literally says - "Find minimum of constrained nonlinear multivariable function"
% Given data
v = [10, 20, 30, 40, 50];
d = [4, 5, 6, 7, 8];
c = [0.05, 0.05, 0.05, 0.05, 0.05];
B = 5;
% Define the objective function to maximize
fun = @(a) -sum(v .* (a ./ (a + d + c)) - a);
% Number of elements (size of v, d, and c)
n = numel(v);
% Set initial guess for 'a' (starting point for the optimization)
% Make sure the initial guess satisfies the constraints: a_i >= 0
initialGuess = [2,2,2,2,2];
% Define the nonlinear inequality constraint: a_i >= 0
nonlincon = @(a) deal([], a);
% Define the linear inequality constraint: sum(a_i) <= B
A = ones(1, n);
b = B;
% Set options for fmincon (optional)
options = optimoptions('fmincon', 'Display', 'iter');
% Perform the constrained optimization
a_optimal = fmincon(@(a) -sum(fun(a)), initialGuess, A, b, [], [], [], [], nonlincon, options);
% Calculate the optimal objective function value
optimal_objective = -fun(a_optimal);
% Display the optimal values of 'a' and the objective function value
disp("Optimal values of 'a':");
disp(a_optimal);
disp("Optimal objective function value:");
disp(optimal_objective);
I have written this code but the values coming of a_optimal are negative. but I have written the a_i>=0 constraint.
Walter Roberson
Walter Roberson el 17 de Ag. de 2023
Movida: Walter Roberson el 21 de Ag. de 2023
Why are you using nonlinear equality constraints for that, when you could simply use lb (lowerbound) ?

Iniciar sesión para comentar.

 Respuesta aceptada

I have corrected your code and added comments (double %) for reference -
% Given data
v = [10, 20, 30, 40, 50];
d = [4, 5, 6, 7, 8];
c = 0.05;
B = 5;
% Define the objective function to maximize
fun = @(a) -sum(v .* (a ./ (a + d + c)) - a);
% Number of elements (size of v, d, and c)
n = numel(v);
% Set initial guess for 'a' (starting point for the optimization)
% Make sure the initial guess satisfies the constraints: a_i >= 0
initialGuess = 2*ones(1,n);
%%There is no non-linear inequality, thus nonlincon is []
% Define the nonlinear inequality constraint: a_i >= 0
nonlincon = [];
%%You need to specify the bounds on the variables -
%Bounds on variables
lb = zeros(1,n);
ub = Inf(1,n);
% Define the linear inequality constraint: sum(a_i) <= B
A = ones(1, n);
b = B;
% Set options for fmincon (optional)
options = optimoptions('fmincon', 'Display', 'iter');
%%Correced the fmincon call to include bounds
% Perform the constrained optimization
a_optimal = fmincon(@(a) fun(a), initialGuess, A, b, [], [], lb, ub, nonlincon, options);
First-order Norm of Iter F-count f(x) Feasibility optimality step 0 6 -2.522299e+01 5.000e+00 1.669e+00 1 12 -1.970688e+01 6.326e-01 9.245e-01 2.600e+00 2 18 -1.778736e+01 0.000e+00 1.905e-01 5.597e-01 3 24 -1.811167e+01 0.000e+00 6.461e-02 2.078e-01 4 30 -1.815469e+01 0.000e+00 3.416e-03 4.387e-02 5 36 -1.815754e+01 0.000e+00 1.003e-03 4.258e-03 6 42 -1.815916e+01 0.000e+00 3.102e-04 3.530e-03 7 48 -1.815956e+01 0.000e+00 1.872e-05 8.340e-04 8 54 -1.815956e+01 0.000e+00 2.323e-06 2.369e-05 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.
% Calculate the optimal objective function value
optimal_objective = -fun(a_optimal);
% Display the optimal values of 'a' and the objective function value
disp("Optimal values of 'a':");
Optimal values of 'a':
disp(a_optimal);
0.0000 0.1433 0.9118 1.6277 2.3172
disp("Optimal objective function value:");
Optimal objective function value:
disp(optimal_objective);
18.1596

Más respuestas (0)

Categorías

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by