西莫电机圈

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

查看: 712|回复: 1

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

[复制链接]

该用户从未签到

发表于 2019-1-21 20:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
% 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
[x,fval,exitflag,output] = 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

评分

参与人数 1西莫币 +3 收起 理由
caiyingui + 3 感谢您的参与

查看全部评分

西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过

该用户从未签到

 楼主| 发表于 2019-1-21 20:21 | 显示全部楼层
没看懂的地方我标注了
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|西莫电机圈 ( 浙ICP备10025899号-3 浙公网安备:33028202000436号

GMT+8, 2024-7-28 14:23 , Processed in 0.508467 second(s), 25 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表