Optimization to minimize output

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
l2 = 7.0711
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(:))
bestP = 0
idx = 1
best_X = X(idx,:)
best_X = 1×3
0 0 0

1 Kommentar

Matt J
Matt J am 6 Okt. 2021
Your post now contains the results of running the code (I took the liberty...). The answer looks correct to me.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 6 Okt. 2021

1 Stimme

% 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
l2 = 7.0711
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(:))
bestP = 0
idx = 1
best_X = X(idx,:)
best_X = 1×3
0 0 0
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 Kommentare

Really sorry. I failed to recognize the obvious earlier. Below is what I wanted to optimize ( a,b,c,d and e) to obtain the minimum power
% Objective:Optimize the lengths to minimze the power using a new variable.
%Constants
k= 2;
w=1;
%Variables
AB = sqrt(a^2 + b^2);
BC = sqrt( c^2 + ((e-d)/2)^2 );
CS = sqrt( c^2 + ((e-d)/2)^2 );
VAB = sqrt(((a*v)^2/((4*b*b)) + (v^2)/2 ));
% VBS = sqrt(((a*v)^2/((4*b*b)) + (v^2)/2 ));
VCS = ((2*c)/(e-d))*sqrt(AB^2);
VBC= CS^2 + BS^2;
%Actual Power
%P = (AB*VAB + BC*VBC + CS*VCS)*k*w; % Power
%
% Objective
%To search and find the values for a, b, c d and eto minimize power
%%% Not sure how to write the function for above%%%%
%Attempt
fun = @(x)(x(:,1) + x(:,2) + x(:,3) + x(:4) + x(5).*k.*w;
[X1, X2, X3, X4, X5] = ndgrid(0:.1:2); % Should I give this condition in a nested loop?
X = [X1(:), X2(:), X3(:), X4(:), X5(:)];
P = fun(X);
[bestP, idx] = min(P(:))
best_X = X(idx,:)
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
I think I missed the relationship constaints. I have included that now. I am not sure how to construct the minimization part, given my relationshipo constrains
% Objective:Optimize the lengths to minimze the power using a new variable.
a = 0.1:20;
b = 0.1:20;
d = a + 0.1:20;
c = b + 0.1:20;
e = d + 0.1:20
%Constants
k= 2;
w=1;
v=1.5
%Variables
AB = sqrt(a.^2 + b.^2);
BC = sqrt( c.^2 + ((e-d)/2).^2 );
CS = sqrt( c.^2 + ((e-d)/2).^2 );
VAB = sqrt(((((a.*v).^2/(((b.^2).*4))) + (v^2)/2 )));
% VBS = sqrt(((a*v)^2/((4*b*b)) + (v^2)/2 ));
VCS = ((2*c)./(e-d)).*sqrt(AB.^2);
VBC= CS.^2 + BC.^2;
%Actual Power
%P = (AB*VAB + BC*VBC + CS*VCS)*k*w; % Power
%
% Objective
%To search and find the values for a, b, c d and eto minimize power
% Not sure how to write the function for above
% fun = @(x)(x(:,1) + x(:,2) + x(:,3) + x(:,4) + x(:,5)).*k.*w;
%
% [X1, X2, X3, X4, X5] = ndgrid(0:.1:2); % Should I give this condition in a nested loop?
%
% X = [X1(:), X2(:), X3(:), X4(:), X5(:)];
%
% P = fun(X);
% [bestP, idx] = min(P(:))
% best_X = X(idx,:)

Melden Sie sich an, um zu kommentieren.

Kategorien

Gefragt:

am 6 Okt. 2021

Kommentiert:

am 6 Okt. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by