% Define parameters and weights
H_L = 1000; % Height on the left
H_R = 500; % Height on the right
R = 7; % Right component size
alpha = 0.5; % Weight for total height
beta = 0.3; % Weight for storage cost
gamma = 0.2; % Weight for imbalance penalty
delta = 0.1; % Weight for aging penalty
lambda = [0.05, 0.05, 0.05, 0.05]; % Weights for security constraints
% Define functions for Aging Penalty and Security Constraints
A = @(p) exp(-p); % Example aging penalty function
C1 = @(p) sin(p); % Example security constraint
C2 = @(p) cos(p);
C3 = @(p) p.^2;
C4 = @(p) sqrt(p);
% Define the storage cost function (choose one)
storage_cost = @(p, L) log(p .* L + 1); % Logarithmic
% storage_cost = @(p, L) p; % Linear
% storage_cost = @(p, L) 1; % Constant
% Define the objective function F(p, L)
F = @(p, L) abs(H_L - H_R) + ...
alpha * (H_L + H_R) + ...
beta * storage_cost(p, L) + ...
gamma * abs((1 - p) .* L - R) + ...
delta * A(p) + ...
lambda(1) * C1(p) + lambda(2) * C2(p) + lambda(3) * C3(p) +
lambda(4) * C4(p);
% Vary p and L to evaluate F(p, L)
p_values = linspace(0.01, 1, 50); % Varying p from 0.01 to 1
L_values = linspace(1, 20, 50); % Varying L from 1 to 20
[P, L_grid] = meshgrid(p_values, L_values); % Create grid for p and L
% Evaluate F(p, L) on the grid
F_values = arrayfun(F, P, L_grid);
% 3D Surface Plot
figure;
subplot(1, 2, 1); % Create a subplot for the 3D surface plot
surf(P, L_grid, F_values, 'EdgeColor', 'none');
xlabel('\bf p', 'FontSize', 14); % Bold label and larger font
ylabel('\bf L', 'FontSize', 14); % Bold label and larger font
zlabel('\bf F(p, L)', 'FontSize', 14); % Bold label and larger font
title('\bf 3D Surface Plot of F(p, L)', 'FontSize', 16); % Bold title and
larger font
set(gca, 'FontSize', 12); % Larger axis markings
colorbar;
grid on;
% Contour Plot
subplot(1, 2, 2); % Create a subplot for the contour plot
contourf(P, L_grid, F_values, 20, 'LineColor', 'none'); % Filled contour
plot
xlabel('\bf p', 'FontSize', 14); % Bold label and larger font
ylabel('\bf L', 'FontSize', 14); % Bold label and larger font
title('\bf Contour Plot of F(p, L)', 'FontSize', 16); % Bold title and
larger font
set(gca, 'FontSize', 12); % Larger axis markings
colorbar;
grid on;