Optimization to minimize output
2 views (last 30 days)
Show older comments
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 Comment
Matt J
on 6 Oct 2021
Your post now contains the results of running the code (I took the liberty...). The answer looks correct to me.
Answers (1)
Walter Roberson
on 6 Oct 2021
% 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 Comments
Walter Roberson
on 6 Oct 2021
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
See Also
Categories
Find more on Get Started with Optimization Toolbox 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!