我第一次尝试使用遗传算法。我犯了一个错误,遇到了麻烦。
使用无法识别的函数或变量‘A_UNFINTED’时出错(第393行)。微处理器_ga_Sanders(第10行)[BEST_X,BEST_OBJECT]=ga(@METPROCER_COST,NVARS,[],lb,ub,@Constraint_Function_微处理器_Sanders,INTCON,OPTIONS)出错,原因:初始用户提供的非线性约束函数求值失败。
我需要一些帮助来评估这个问题。我已经为此工作了几个小时,但还是想不出来。
clc
clear
close all
options = optimoptions('ga','Display','iter','ConstraintTolerance',0);
NVARS=3;
lb=[1, 0.0005, 0.0005];
ub=[30, 0.03, 0.03];
INTCON = [1];
[best_X,best_Objective] = ga(@microprocessor_cost,NVARS,[],[],[],[],lb,ub,@Constraint_function_microprocessor_Sanders,INTCON,options)
我将附加我在代码中引用的所有函数。
目标函数:
function [cost] = microprocessor_cost(X)
%function to determine the cost of an aluminum, rectangular heat sink
% N is the number of fins
% L is the length of the fins
% t is the thickness of fins
% b is the height of the base of the heat sink
w=0.0508; %w and r are hardcoded for the specific problem
r=0.0508;
b=0.002;
N=X(:,1);
L=X(:,2);
t=X(:,3);
volume_base=b*w*r;
volume_fins=L*w*t*N;
volume_total=volume_base+volume_fins;
cost=volume_total*849064;
end
约束函数:
function [C, Ceq] = Constraint_function_microprocessor_Sanders(X)
%C is vector of inequality constraints. GA keeps it less than zero, i.e. C<0 and only solutions with C<0 are feasible
%Ceq is vecor of equality constraints (we have none). GA keeps it equal to zero, i.e. Ceq=0, and only solutions with Ceq=0 ARE FEASIBLE
Resistance = resistance_microprocessor(X);
%the following will make unrealistic designs infeasible
if A_unfinned<0
Resistance = 1000;
end
Target_Resistance=50/15;
C = Resistance - Target_Resistance; % C<0, implies Resistance<Target_Resistance
Ceq = [];
end
阻力函数:
function [Resistance] = resistance_microprocessor(X)
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
%2in by 2in microprocessor - assuming that the width and length of the heat
%sink is equal to the width and length of the microprocessor
%2in = 0.0508m
w=0.0508; %m
l=0.0508; %m 2x2 inch microprocessor
fins=X(:,1);
L=X(:,2);
t=X(:,3);
%assuming no thermal grease between microprocessor and heat sink
contact_resistance_per_area=0.001; %K/(W*m^2)
Tamb=30+273; %K
v=0.000021; %m^2/s
Pr=0.7;
k_air=0.03; %W/(m*K)
%% Design deciscions
Tambient=293; %K, ambient air temperature
b=0.002; %m, height of base of heat sink
k=240; %W/(m*K), aluminum fins
%% Calculations
%calculated, (80+30)/2 = 55, (55+80)/2 = 42.5
Tfilm=42.5+273; %K
%chosen length of fins: 75 mm, which is the maximum length, Lc for vertical
%plate = L
Lc=0.075; %m,
%solve for natural convection coefficient
h=function_get_convection_coefficient(Tfilm,Tamb,Lc,v,Pr,k_air); %W/m^2
%constraint - must be able to dissipate 15 W
q=15; %W
%thermal network calculations - thermal resistances
%contact resistance
area_transistor=w*l;
R_contact=contact_resistance_per_area*area_transistor;
%resistance - conduction through base
A_base=l*w;
R_base=b/(k*A_base);
%fin thermal resistance - convection
n=function_get_fin_efficiency(h,L,t,w,k); %fin efficiency using function
surf_area_fins=fins*2*(L*w); %ignoring the convection through the end and through top and bottom
R_fins=1/(h*surf_area_fins*n);
%unfinned thermal resistance
A_unfinned=(l-(fins*t))*w;
R_unfinned=1/(h*A_unfinned);
%overall thermal resistance of system
Resistance=R_contact+R_base+(1/(1/R_fins)+(1/R_unfinned));
end
1条答案
按热度按时间1l5u6lss1#
实际上,错误输出直接告诉您问题出在哪里。在您的函数
Constraint_function_microprocessor_Sanders
中,变量A_unfinned
不存在。要解决这个问题,您可能需要从函数
resistance_microprocessor(X)
传递它。这意味着,需要进行以下更改:1.将
function [Resistance] = resistance_microprocessor(X)
改为function [Resistance,A_unfinned] = resistance_microprocessor(X)
1.在函数
Constraint_function_microprocessor_Sanders
中,将Resistance = resistance_microprocessor(X);
更改为[Resistance,A_unfinned] = resistance_microprocessor(X);
如果没有其他问题,这可能会有所帮助。
解决这一问题的另一种可能性可能是
到
resistance_microprocessor
函数的末尾。