Objective function problem using "fmincon"

5 ビュー (過去 30 日間)
Teva PM
Teva PM 2020 年 4 月 23 日
コメント済み: Teva PM 2020 年 4 月 23 日
Dear Community,
I work on the optimization of the lift-coefficient of an airfoil. My goal is to know how to do that with a genetic algorithm, but I prefer beginnig with something easier.
Here is my main code :
[Xinit,Yinit,XU,YU,XL,YL] = airfoil_coord('NACA0012'); %load Xinit=[Xlower,Xupper] Yinit=[Ylower,Yupper] : (x,y)coordinates NACA0012
fun = @(YN)airfoilcoord(YN,CLtarget,Xinit,alpha,Re,M)
CLtarget = 0.6; %I assume here that {CLinit=0.4610} so {CLtarget=0.6} would be an optimization
alpha =4; %Flight conditons
Re = 32000000; %Flight conditons
M = 0.1764; %Flight conditons
% lb = transpose(ones(1,199)*(-0.08)); %I assume to not enforce a lower and upper bounds
% ub = transpose(ones(1,199)*(0.08));
% Code optimization
[Yopti]=fmincon(fun,Yinit,[],[],[],[]);
Here are the functions used in the code:
function error = airfoilcoord(YN,CLtarget,Xcoord, alpha, Re, M)
%
CL = run_xfoil(Xcoord, YN, alpha, Re, M); %I want the YN vector to change in every loop
error = (CLtarget - CL)
function [CL] = run_xfoil(xcoord, ycoord, alpha, Re, M)
for i=1:length(ycoord)
ycoordxfoil(i)=ycoord(200-i);
end
for i=1:length(xcoord)
xcoordxfoil(i)=xcoord(200-i);
end
Profil = [transpose(xcoordxfoil) , transpose(ycoordxfoil)];
%Necessary to use the XFOIL software
% Function xfoil in the directory
[pol,foil] = xfoil(Profil, alpha, Re, M, 'oper/iter 5000');
CL = pol.CL; %Return a double which is the CL for the airfoil represented as : (xcoord,yccord)
Here is my problem :
When I evaluate each member alone, it works well. But when I run the code, there is not improvement, the CL and the vector YN stay the same at each loop. I think there is a little mistake in my code but I can't find where..
Can someone help me ? Thank you for reading and the time you'll take to answer !
Teva

採用された回答

John D'Errico
John D'Errico 2020 年 4 月 23 日
Whenever you have an optimization problem, a good first step is to verify that IF you pass in two slightly different set of parameters to your objective, you get a different result. We cannot test that, since we don't have the complete code. So, does the software produce a result that does not change for slightly different inputs?
  1 件のコメント
Teva PM
Teva PM 2020 年 4 月 23 日
I tried two different airfoils (NACA0012 and NACA4412), then I tried to modify my flight conditions (angle of attack, Reynolds, Mach). The result is different, so "Error" does not give me the same result. But it makes an unlimited loop without any optimization, at each loop I have the same "YN" and the same "Error".. Maybe would you me to send you the entire code ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAirfoil tools についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by