HUST_EE 发表于 2019-1-21 20:20

这是一段ansys官方提供的利用matlab工具箱对电机模型进行优化的程序,有几个地方没看懂

% make sure platform matches
if strcmp(computer, '$ANS_EXPECTED_PLATFORM') ~= 1
h = msgbox('32/64 platform does not match calling application, exiting')
uiwait(h)
exit
end

% add installation dir to search path so .mex file can be found
originalpath = addpath('$ANS_EXEDIR')

% connect back to opticomengine
callbackinterface = optimex('connect', '$ANS_CONNECTIONSTRING')

% make sure the optimization toolbox license can be checkout out
if license('checkout','optimization_toolbox') ~= 1
h = msgbox('Optimization Toolbox not licensed, exiting')
uiwait(h)
exit
end

% set up optimization
% variables are: $ANS_VARIABLELIST
startingpoint = $ANS_STARTINGPOINT
options = optimset('MaxIter', $ANS_MAXITERATIONS)
iterationCallbackWrapper = @(x, optimValues, state) optimex('notifyiterationcomplete', callbackinterface, x, optimValues.fval, state)
options = optimset(options, 'OutputFcn', iterationCallbackWrapper)

% halt execution so debugger can be attached
% h = msgbox('attach debugger if desired')
% uiwait(h)

% attributes that user can pass to optimization algorithm
% variables are: $ANS_VARIABLELIST

% this is the objective function which returns cost
wrapperfunc = @(x)optimex('eval', callbackinterface, x)

% this is our non linear constraint function, returns no constraints
returnempty = @(x)[];
nlcon = @(x) deal(returnempty(x), returnempty(x));

% DO NOT EDIT THIS LINE - START OPTIONS SECTION

% customers can add their own options below
options = optimset(options, 'display', 'iter')
options = optimset(options, 'Algorithm', 'interior-point')
% options = optimset(options, 'PlotFcns', @optimplotfval)

% DO NOT EDIT THIS LINE - END OPTIONS SECTION
% DO NOT EDIT THIS LINE - START OPTIMIZATION ALGO SECTION
% invoke optimization
= fmincon(wrapperfunc, startingpoint, $ANS_A_MATRIX, $ANS_B_MATRIX, [], [], $ANS_MINVAL, $ANS_MAXVAL, nlcon, options)

% DO NOT EDIT THIS LINE - END OPTIMIZATION ALGO SECTION

% write exit message to Ansoft message window (warning=0,error=1,info=2)
optimex('postansoftmessage', callbackinterface, 2, output.message)

% notify opticomengine that optimization is finished
optimex('optimizationfinished', callbackinterface, exitflag)

% restore original path
path = originalpath

% note: comment below line if you want MATLAB to remain
% running after optimization
exit

HUST_EE 发表于 2019-1-21 20:21

没看懂的地方我标注了
页: [1]
查看完整版本: 这是一段ansys官方提供的利用matlab工具箱对电机模型进行优化的程序,有几个地方没看懂