Optimization to minimize output
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to optimize the lengths to minimize the power ( details in the code)
I am unable to proceed with the optimization part. ( Iam not getting the expected result of optimized power)
Any help would be greatly appreciated.
% Objective:Optimize the lengths to minimze the power using a new variable.
%Constants
k= 1;
w=1;
%Variable lengths
l1 = 3*(5)^0.5;
l2 = 5*(2)^0.5
l3 = sqrt(5);
v1 = sqrt(5);
v2 = 2*sqrt(2);
v3 = 2*sqrt(5);
% Expressing the l and v in terms of a b and c. Open to expressing differently
% if it helps the objective below.
a = l1*v1;
b = l2*v2;
c = l3*v3;
%Actual Power
P = (l1*v1 + l2*v2 + l3*v3)*k*w; % Power
% Objective
%To search and find the values for a, b and c to minimize power
%Considering x to represent a,b and c.
fun = @(x)(x(:,1) + x(:,2) + x(:,3)).*k.*w;
[X1, X2, X3] = ndgrid(0:.1:2); % Should I give this condition in a nested loop?
X = [X1(:), X2(:), X3(:)];
P = fun(X);
[bestP, idx] = min(P(:))
best_X = X(idx,:)
1 个评论
Matt J
2021-10-6
Your post now contains the results of running the code (I took the liberty...). The answer looks correct to me.
回答(1 个)
Walter Roberson
2021-10-6
% Objective:Optimize the lengths to minimze the power using a new variable.
%Constants
k= 1;
w=1;
%Variable lengths
l1 = 3*(5)^0.5;
l2 = 5*(2)^0.5
l3 = sqrt(5);
v1 = sqrt(5);
v2 = 2*sqrt(2);
v3 = 2*sqrt(5);
% Expressing the l and v in terms of a b and c. Open to expressing differently
% if it helps the objective below.
a = l1*v1;
b = l2*v2;
c = l3*v3;
%Actual Power
P = (l1*v1 + l2*v2 + l3*v3)*k*w; % Power
% Objective
%To search and find the values for a, b and c to minimize power
%Considering x to represent a,b and c.
fun = @(x)(x(:,1) + x(:,2) + x(:,3)).*k.*w;
[X1, X2, X3] = ndgrid(0:.1:2); % Should I give this condition in a nested loop?
X = [X1(:), X2(:), X3(:)];
P = fun(X);
[bestP, idx] = min(P(:))
best_X = X(idx,:)
This is obviously the correct output for the formula.
k is positive. w is positive. k*w is positive. k*w is being multiplied by (x1 + x2 + x3)
To get the smallest result of a multiplication of a positive number and another number, you want the second number to be as small as possible.
Your x1, x2, x3 are all bounded by 0 below. Increasing x1 or x2 or x3 would increase the sum x1+x2+x3 . So the smallest x1+x2+x3 is at the lower bound, where x1 = x2 = x3 = 0.
So your minima is clearly at x1 = x2 = x3 = 0 with power 0 .
3 个评论
Walter Roberson
2021-10-6
fun = @(x)(x(:,1) + x(:,2) + x(:,3) + x(:4) + x(5).*k.*w;
missing close bracket
has same issue as before with minima at 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!