MATLAB Answers

0

Finding a maximum using gamultobj tool

Asked by Daniel Harper on 4 Mar 2019
Latest activity Commented on by Stephan
on 4 Mar 2019
Hi, i've written the following script and I'm looking to maximise y(2) using the gamultobj tool. However I can only seem to find the minimum value. How can I find the maximum? (I'm using bounds [ 0 4 0 4 0 4] lower and [20 8 20 8 20 8] upper)
function [y] = totalpowertest(x)
% beta1 x(1) beta3 x(5)
% lamda1 x(2) lamda3 x(6)
% beta2 x(3)
% lamda2 x(4)
rho = 1.225; % density of air kg/m^3
R = 89.15; % radius of turbine m
D = 178.3; % diameter of turbine m
k = 0.04;
xd = 178.3*5; %example value for distance between turbines
u1 = 15; % example value
c1 = 0.5176;
c2 = 116;
c3 = 0.4;
c4 = 5;
c5 = 21;
c6 = 0.0068;
% equation 1 lamdai1
z1 = 1/(x(2) + 0.08*x(1)) - 0.035/((x(1).^3) +1);
lamdai1 =1/z1;
%equation 2 cp1
cp1 = c1*((c2/lamdai1)-c3*x(1)-c4)*exp(-c5/lamdai1)+c6*x(2);
%equation 3 u4 (z3)
Z3 = roots([ 1/(2*u1^3), 1/(2*u1^2), -1/(2*u1), cp1 - 1/2]);
z3 = real(Z3( Z3>0 ));
u4 = z3;
%equation 3ii u2
u2 = 0.5*(u1+u4);
%equation 3iii T
T = rho*pi*(R.^2)*u2*(u1-u4);
%equation 3iv (for second turbine) ct
%u1 istead of u4?
ct = (2*T)/(rho*pi*(R.^2)*(u1.^2));
%equation 4 (for second turbine) vw
vw = u1*(1-((R/(k*xd+R)).^2)*(1-sqrt(1-ct)));
% equation 5i (for first turbine) - maximum 10 MW allowed pout1
a1 = 0.5*cp1*rho*pi*R.^2*u1.^3;
a1(a1>10000000)=10000000;
pout1 = a1;
% equation 1 lamdai2
z3 = 1/(x(4) + 0.08*x(3)) - 0.035/((x(3).^3) +1);
lamdai2 = 1/z3;
%equation 2 cp2
cp2 = c1*((c2/lamdai2)-c3*x(3)-c4)*exp(-c5/lamdai2)+c6*x(4);
% equation 5ii (for second turbine) - maximum 10 MW allowed pout2
a2 = 0.5*cp2*rho*pi*R.^2*vw.^3;
a2(a2>10000000)=10000000;
pout2 = a2;
% equation 6 pout1+pout2
y(1) = pout1 + pout2;
%u1_3 = u4_2; % downstream wind of first turbine to calculate power of second turbine
%u1_3 = y(3); % is equal to incoming windspeed of second turbine to calclate power of third turbine
% equation 1 (for third turbine) lamdai
z4 = 1/(x(6) + 0.08*x(5)) - 0.035/((x(5).^3) +1);
lamdai3 =1/z4;
%equation 2 (for third turbine) cp
cp3 = c1*((c2/lamdai3)-c3*x(5)-c4)*exp(-c5/lamdai3)+c6*x(6);
%equation 3i_3 (for third turbine) u4 (z5?)
Z5 = roots([ 1/(2*u4^3), 1/(2*u4^2), -1/(2*u4), cp2 - 1/2]);
z5 = real(Z5( Z5>0 ));
u4_2=z5;
%
%equation 3ii_3 (for third turbine) u2
u2_2 = 0.5*(u4+u4_2);
%equation 3iii_3 (for third turbine) T
T_2 = rho*pi*(R.^2)*u2_2*(u4-u4_2);
%equation 3iv_3 (for third turbine) ct
ct_2 = (2*T_2)/(rho*pi*(R.^2)*(u4.^2));
%equation 4_2 (for third turbine) vw
vw_2 = u4*(1-((R/(k*xd+R)).^2)*(1-sqrt(1-ct_2)));
% equation 5_3 (for third turbine) - maximum 10 MW allowed pout3
a3 = 0.5*cp3*rho*pi*R.^2*vw_2.^3;
a3(a3>10000000)=10000000;
pout3 = a3;
% equation 6 pout1 + pout2 + pout3
y(2) = pout1 + pout2 + pout3;
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephan
on 4 Mar 2019
Edited by Stephan
on 4 Mar 2019
 Accepted Answer

Hi,
all optimizers in Matlab try ti find minimum of functions. If you want to maximize you simply minimize the negative function.
max (f) --> min (-f)
See also here:
Best regards
Stephan

  10 Comments

y = -(pout1 + pout2 + pout3);
for one variable you can write y instead of y(1)
The result should be the negative value of your desired maximum.
Cheers thanks very much! Just one last question. Is there any way to show the values of the other parameters for the maximum result (i.e. cp and u4)?
mmh, one way would be an adapted copy of your function eith the desired outputs. once you have the result you could call this second function with the optimized vector of variables and get the result this way. for a more clever solution i qould have to think a bit longer. but im a bit in hurry currently.
if this answer was useful please accept it.

Sign in to comment.