minimzing the expression to find the variables
2 次查看(过去 30 天)
显示 更早的评论
i want to perform minimzation to get the values of variable,
i have the following given data:
a=[3.85094026548672, 18.1807706489675, 22.0685840707964, 22.036320058997, 22.0040560471976, 21.9833148967551, 21.9441371681415, 24.511430678466, 24.4791666666666, 24.45151179941, 24.4330752212389, 24.410029498525, 30.9112278761062, 36.1149520648967, 41.3163716814159, 45.2203171091445]
b=b=[957.522123893805, 962.831858407079, 948.672566371681, 923.893805309734, 899.115044247787, 883.185840707964, 853.097345132743, 824.778761061946, 799.999999999999, 778.761061946902, 764.601769911504, 746.902654867256, 739.823008849557, 736.283185840707, 730.973451327433, 729.203539823008]
lb_x=[3.8509,30.9112,63.4418,3.5698,3.2909,17.6254,0.2120,27.5857,65.7679,32.7733, 157.6696,67.318860619469, 64.4704092920354, 85.1124631268436, 128.037426253687, 152.502765486725]
similarly i have values for ub_x, lb_y, ub_y, lb_w, ub_w, reg1, reg2
for i = 1:numel(a)
r1 = reg1(i);
r2 = reg2(i);
expr = expr + w(r2) * (sqrt((x(r1)-a(i))^2 + (y(r1)-b(i))^2)) - w(r1) * (sqrt((x(r2)-a(i))^2 + (y(r2)-b(i))^2));
end
i want to minimize expr = expr + w(r2) * (sqrt((x(r1)-a(i))^2 + (y(r1)-b(i))^2)) - w(r1) * (sqrt((x(r2)-a(i))^2 + (y(r2)-b(i))^2)), in order to get the different values of x,y and w
for k=1:26
x.LowerBound(k)=lb_x(k);
x.UpperBound(k)=ub_x(k);
y.LowerBound(k)=lb_y(k);
y.UpperBound(k)=ub_y(k);
w.LowerBound(k)=lb_w(k);
w.UpperBound(k)=ub_w(k);
end
showbounds(x)
showbounds(y)
showbounds(w)
Kindly suggest a way to perform this minimzation
2 个评论
采纳的回答
Hassaan
2024-1-14
% Your given data
a = [...]; % Define your array
b = [...]; % Define your array
reg1 = [...]; % Define your array
reg2 = [...]; % Define your array
lb_x = [...]; % Lower bounds for x
ub_x = [...]; % Upper bounds for x
lb_y = [...]; % Lower bounds for y
ub_y = [...]; % Upper bounds for y
lb_w = [...]; % Lower bounds for w
ub_w = [...]; % Upper bounds for w
% Initial guesses
initial_x = zeros(1, 26);
initial_y = zeros(1, 26);
initial_w = zeros(1, 26);
% Concatenating initial guesses, lower bounds, and upper bounds
initialVars = [initial_x, initial_y, initial_w];
lb = [lb_x, lb_y, lb_w];
ub = [ub_x, ub_y, ub_w];
% Optimization options
options = optimoptions('fmincon', 'Display', 'iter', 'Algorithm', 'sqp');
% Define the objective function directly in the script
objFun = @(vars) objective(vars, a, b, reg1, reg2);
% Run optimization
[optimalVars, fval] = fmincon(objFun, initialVars, [], [], [], [], lb, ub, [], options);
% Extract optimal x, y, and w
optimal_x = optimalVars(1:26);
optimal_y = optimalVars(27:52);
optimal_w = optimalVars(53:end);
% Display results
disp('Optimal x:');
disp(optimal_x);
disp('Optimal y:');
disp(optimal_y);
disp('Optimal w:');
disp(optimal_w);
disp('Objective function value:');
disp(fval);
% Objective function
function f = objective(vars, a, b, reg1, reg2)
x = vars(1:26);
y = vars(27:52);
w = vars(53:end);
f = 0;
for i = 1:numel(a)
r1 = reg1(i);
r2 = reg2(i);
f = f + w(r2) * sqrt((x(r1)-a(i))^2 + (y(r1)-b(i))^2) - w(r1) * sqrt((x(r2)-a(i))^2 + (y(r2)-b(i))^2);
end
end
Need to replace the [...] parts with your actual data.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!