Calculate f for multiple inputs

1 view (last 30 days)
Arashdeep Dhillon
Arashdeep Dhillon on 2 May 2021
Answered: Sanju on 19 Feb 2024
I want to calculate the function f for multiple inputs and then find the number of local and global minima.
% Import the excel data into MATLAB
T = readtable('Task1.xlsx','Range','A7:F106');
% Calculate the function f and find the number of local and global minima
q = T(1:99,4);
x = T(1:99,2);
y = T(1:99,3);
cost = T(1:99,6);
u = [0:100];
v = [0:100];
for i = 1:100
f = sum(q(i)*((u-x).^2) + ((v-y).^2))
end

Answers (1)

Sanju
Sanju on 19 Feb 2024
To calculate the function “f” for multiple inputs, I have updated the code as follows,
% Import the excel data into MATLAB
T = readtable('Task1.xlsx','Range','A7:F106');
% Calculate the function f and find the number of local and global minima
q = T(1:99,4);
x = T(1:99,2);
y = T(1:99,3);
cost = T(1:99,6);
u = 0:100;
v = 0:100;
f_values = zeros(length(u), length(v));
for i = 1:length(u)
for j = 1:length(v)
f_values(i,j) = sum(q.*((u(i)-x).^2) + ((v(j)-y).^2));
end
end
To find the number of local and global minima, you can refer to the below implementation,
% Find the number of local and global minima
num_local_minima = sum(imregionalmin(f_values));
num_global_minima = sum(f_values(:) == min(f_values(:)));
You can also refer to the below documentation on “imregionalmin” function if required,
Hope this helps!

Categories

Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!