“常用公式”在线计算,“设计手册”在线查询
楼主
石光 新来的 发表于 2014-6-1 14:23:41 | 显示全部楼层
你可以看matlab的帮助文档里面的Passing Extra Parameters这一节,讲了有三种方法给优化的目标函数传递独立变量,要用并行的话不能使用全局变量的方法,可以采用匿名函数的方法。Write an M-file containing the following code:function y = parameterfun(x,a,b,c)y = (a - b*x(1)^2 + x(1)^4/3)*x(1)^2 + x(1)*x(2) + ...(-c + c*x(2)^2)*x(2)^2;Assign values to the parameters and define a functionhandle f to an anonymous function by entering thefollowing commands at the MATLAB prompt:a = 4; b = 2.1; c = 4; % Assign parameter valuesx0 = [0.5,0.5];f = @(x)parameterfun(x,a,b,c)Call the solver fminunc withthe anonymous function:[x,fval] = fminunc(f,x0)f就是已经传递了独立变量的目标函数的函数句柄上面的例子是用 fminunc求解的,用ga也一样
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注我们

360网站安全检测平台