Objective function problem using "fmincon"

5 views (last 30 days)
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

Accepted Answer

John D'Errico
John D'Errico on 23 Apr 2020
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 Comment
Teva PM
Teva PM on 23 Apr 2020
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 ?

Sign in to comment.

More Answers (0)

Categories

Find more on Airfoil tools in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!