Objective function problem using "fmincon"

조회 수: 4 (최근 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 CenterFile Exchange에서 Airfoil tools에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by