nonlinear constraint game theory
4 views (last 30 days)
Show older comments
Plzz solve this problem in matlab.
5 Comments
Answers (1)
Torsten
on 6 Nov 2023
Edited: Torsten
on 7 Nov 2023
By the way: What do you mean by "nonlinear constraint game theory" ? Your constraints are all linear.
% Define the objective function
n = 5; % Set your desired value for n
k = 0.2; % Set your desired value for k
C = 100; % Set your desired value for C
V_i = [10; 10; 10; 10; 10];
% Generate random initial values for a_i
initial_a = ones(n, 1);
% Generate random data for d_i and V_i
d_i = [2.5; 2.5; 2.5; 2.5; 2.5]; % Replace with your actual data
% Define the anonymous objective function
objective = @(a) -sum(V_i .* exp(-k * (d_i ./ a)) - a);
% Define the nonlinear inequality constraint
%nonlcon = @(a) deal(C - sum(a), []); % Return an empty array for equality constraints
A = ones(1,n);
b = C;
% Set up optimization options
options = optimoptions('fmincon', 'Display', 'iter');
% Solve the optimization problem
%result = fmincon(objective, initial_a, A, b, [], [], zeros(n, 1), [], nonlcon, options);
result = fmincon(objective, initial_a, A, b, [], [], zeros(n, 1), inf(n,1), [], options);
% Extract the optimized values of a_i
optimal_a = result;
% Evaluate the objective function with the optimal values of a_i
optimal_objective_value = objective(optimal_a);
% Display the optimal solution and objective function value
disp('Optimal values of a_i:')
disp(optimal_a);
disp(['Optimal Objective Function Value: ', num2str(-optimal_objective_value)]);
% Define the objective function
n = 5; % Set your desired value for n
k = 0.2; % Set your desired value for k
B = 60; % Set your desired value for C
V_i = [10; 10; 10; 10; 10];
% Generate random initial values for a_i
initial_d = ones(n, 1);
% Generate random data for d_i and V_i
a = [2.5; 2.5; 2.5; 2.5; 2.5]; % Replace with your actual data
% Define the anonymous objective function
objective = @(d) sum(V_i .* exp(-k * (d ./ a)) + d);
% Define the nonlinear inequality constraint
%nonlcon = @(d) deal(B - sum(d), []); % Return an empty array for equality constraints
A = ones(1,n);
b = B;
% Set up optimization options
options = optimoptions('fmincon', 'Display', 'iter');
% Solve the optimization problem
result = fmincon(objective, initial_d, A, b, [], [], zeros(n, 1), inf(n,1), [], options);
% Extract the optimized values of a_i
optimal_d = result;
% Evaluate the objective function with the optimal values of a_i
optimal_objective_value = objective(optimal_d);
% Display the optimal solution and objective function value
disp('Optimal values of d_i:')
disp(optimal_d);
disp(['Optimal Objective Function Value: ', num2str(optimal_objective_value)]);
3 Comments
Torsten
on 7 Nov 2023
Also the output I want is with increase in the value of C the optimal objective value for maximization case will increase. And with increase in the value of B optimal objective value for minimization case will decrease.
Your model is now correctly implemented. If you expect a different behaviour of the solution, then either your model is wrong or it has multiple local maxima and/or minima. In the last case, you could try with different initial values for a and d.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!