| 查看: 3966 | 回复: 8 | ||||
[求助]
matlab下用遗传算法求最小值的问题
|
|
刚刚接触matlab,有点问题求解答 现有这样一个方程:VRRm=0.2355-0.637*10-4x1+1.85875*10-4x2+0.82225*10-2x3-0.1715x4-1.6725*10-6x1*x2+0.966925*10-4x1*x3+0.403*10-4x2*x3-0.471*10-2x3*x4 x1、x2、x3、x4都有上下限,想借助matlab用遗传算法求VRR的最小值,自己编写一个程序麻烦吗,或者使用matlab遗传算法工具箱能实现吗? |
» 猜你喜欢
Cas 72-43-5需要30g,定制合成,能接单的留言
已经有8人回复
求助:我三月中下旬出站,青基依托单位怎么办?
已经有6人回复
北京211副教授,35岁,想重新出发,去国外做博后,怎么样?
已经有8人回复
磺酰氟产物,毕不了业了!
已经有5人回复
论文终于录用啦!满足毕业条件了
已经有25人回复
2026年机械制造与材料应用国际会议 (ICMMMA 2026)
已经有3人回复
自荐读博
已经有3人回复
不自信的我
已经有5人回复
投稿Elsevier的杂志(返修),总是在选择OA和subscription界面被踢皮球
已经有8人回复
» 本主题相关价值贴推荐,对您同样有帮助:
matlab中如何调用delphi编写的程序?
已经有4人回复
matlab 遗传算法工具箱gaot gatbx下载
已经有183人回复
求教matlab线性优化求最小值的问题
已经有7人回复
求助:遗传算法的matlab编程求解资源优化问题
已经有7人回复
matlab论文分享(包括神经网络,遗传算法,粒子群算法)
已经有442人回复
matlab中是否可以用simulink实现遗传算法
已经有6人回复
如何MATLAB程序实现遗传算法
已经有11人回复
MATLAB用于三元回归参数
已经有3人回复
一个关于matlab的遗传算法的问题
已经有3人回复
求回归方程参数估计的最优化算法matlab代码
已经有9人回复
【分享】matlab遗传算法工具箱与应用(雷英杰)【已搜索无重复】
已经有74人回复
【求助】matlab 二次规划的优化的问题
已经有4人回复
【求助】matlab 遗传算法工具箱绘图命令是什么?
已经有6人回复
2楼2013-11-21 13:01:58
feifeiyin12
铁虫 (初入文坛)
- 应助: 1 (幼儿园)
- 金币: 155.5
- 红花: 1
- 帖子: 35
- 在线: 20.6小时
- 虫号: 2767705
- 注册: 2013-10-31
- 性别: GG
- 专业: 空间物理

3楼2013-11-21 13:28:04
4楼2013-11-21 14:08:03
月只蓝
主管区长 (职业作家)
-

专家经验: +1059 - 应助: 1712 (讲师)
- 贵宾: 8.888
- 金币: 68123.7
- 散金: 1938
- 红花: 443
- 沙发: 4
- 帖子: 4373
- 在线: 3291.4小时
- 虫号: 1122189
- 注册: 2010-10-14
- 专业: 宇宙学
- 管辖: 计算模拟区

5楼2013-11-21 16:06:11
6楼2013-11-21 16:53:14
月只蓝
主管区长 (职业作家)
-

专家经验: +1059 - 应助: 1712 (讲师)
- 贵宾: 8.888
- 金币: 68123.7
- 散金: 1938
- 红花: 443
- 沙发: 4
- 帖子: 4373
- 在线: 3291.4小时
- 虫号: 1122189
- 注册: 2010-10-14
- 专业: 宇宙学
- 管辖: 计算模拟区
【答案】应助回帖
|
MATLAB有自带的遗传算法函数ga,虽然说MATLAB的内置的遗传算法并不是最优秀的,但求解你的问题应该没问题。 ga函数调用格式很方便,见MATLAB help: GA Constrained optimization using genetic algorithm. GA attempts to solve problems of the form: min F(X) subject to: A*X <= B, Aeq*X = Beq (linear constraints) X C(X) <= 0, Ceq(X) = 0 (nonlinear constraints) LB <= X <= ub X = GA(FITNESSFCN,NVARS) finds a local unconstrained minimum X to the FITNESSFCN using GA. NVARS is the dimension (number of design variables) of the FITNESSFCN. FITNESSFCN accepts a vector X of size 1-by-NVARS, and returns a scalar evaluated at X. X = GA(FITNESSFCN,NVARS,A,b) finds a local minimum X to the function FITNESSFCN, subject to the linear inequalities A*X <= B. Linear constraints are not satisfied when the PopulationType option is set to 'bitString' or 'custom'. See the documentation for details. X = GA(FITNESSFCN,NVARS,A,b,Aeq,beq) finds a local minimum X to the function FITNESSFCN, subject to the linear equalities Aeq*X = beq as well as A*X <= B. (Set A=[] and B=[] if no inequalities exist.) Linear constraints are not satisfied when the PopulationType option is set to 'bitString' or 'custom'. See the documentation for details. X = GA(FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables, X, so that a solution is found in the range lb <= X <= ub. Use empty matrices for lb and ub if no bounds exist. Set lb(i) = -Inf if X(i) is unbounded below; set ub(i) = Inf if X(i) is unbounded above. Linear constraints are not satisfied when the PopulationType option is set to 'bitString' or 'custom'. See the documentation for details. X = GA(FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub,NONLCON) subjects the minimization to the constraints defined in NONLCON. The function NONLCON accepts X and returns the vectors C and Ceq, representing the nonlinear inequalities and equalities respectively. GA minimizes FITNESSFCN such that C(X)<=0 and Ceq(X)=0. (Set lb=[] and/or ub=[] if no bounds exist.) Nonlinear constraints are not satisfied when the PopulationType option is set to 'bitString' or 'custom'. See the documentation for details. X = GA(FITNESSFCN,NVARS,A,b,Aeq,beq,lb,ub,NONLCON,options) minimizes with the default optimization parameters replaced by values in the structure OPTIONS. OPTIONS can be created with the GAOPTIMSET function. See GAOPTIMSET for details. X = GA(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a structure that has the following fields: fitnessfcn: <Fitness function> nvars: <Number of design variables> Aineq: <A matrix for inequality constraints> bineq: <b vector for inequality constraints> Aeq: <Aeq matrix for equality constraints> beq: <beq vector for equality constraints> lb: <Lower bound on X> ub: <Upper bound on X> nonlcon: <nonlinear constraint function> options: <Options structure created with GAOPTIMSET> rngstate: <State of the random number generator> [X,FVAL] = GA(FITNESSFCN, ...) returns FVAL, the value of the fitness function FITNESSFCN at the solution X. [X,FVAL,EXITFLAG] = GA(FITNESSFCN, ...) returns EXITFLAG which describes the exit condition of GA. Possible values of EXITFLAG and the corresponding exit conditions are 1 Average change in value of the fitness function over options.StallGenLimit generations less than options.TolFun and constraint violation less than options.TolCon. 3 The value of the fitness function did not change in options.StallGenLimit generations and constraint violation less than options.TolCon. 4 Magnitude of step smaller than machine precision and constraint violation less than options.TolCon. This exit condition applies only to nonlinear constraints. 5 Fitness limit reached and constraint violation less than options.TolCon. 0 Maximum number of generations exceeded. -1 Optimization terminated by the output or plot function. -2 No feasible point found. -4 Stall time limit exceeded. -5 Time limit exceeded. [X,FVAL,EXITFLAG,OUTPUT] = GA(FITNESSFCN, ...) returns a structure OUTPUT with the following information: rngstate: <State of the random number generator before GA started> generations: <Total generations, excluding HybridFcn iterations> funccount: <Total function evaluations> maxconstraint: <Maximum constraint violation>, if any message: <GA termination message> [X,FVAL,EXITFLAG,OUTPUT,POPULATION] = GA(FITNESSFCN, ...) returns the final POPULATION at termination. [X,FVAL,EXITFLAG,OUTPUT,POPULATION,SCORES] = GA(FITNESSFCN, ...) returns the SCORES of the final POPULATION. Example: Unconstrained minimization of 'rastriginsfcn' fitness function of numberOfVariables = 2 x = ga(@rastriginsfcn,2) Display plotting functions while GA minimizes options = gaoptimset('PlotFcns',... {@gaplotbestf,@gaplotbestindiv,@gaplotexpectation,@gaplotstopping}); [x,fval,exitflag,output] = ga(@rastriginsfcn,2,[],[],[],[],[],[],[],options) An example with inequality constraints and lower bounds A = [1 1; -1 2; 2 1]; b = [2; 2; 3]; lb = zeros(2,1); % Use mutation function which can handle constraints options = gaoptimset('MutationFcn',@mutationadaptfeasible); [x,fval,exitflag] = ga(@lincontest6,2,A,b,[],[],lb,[],[],options); FITNESSFCN can also be an anonymous function: x = ga(@(x) 3*sin(x(1))+exp(x(2)),2) If FITNESSFCN or NONLCON are parameterized, you can use anonymous functions to capture the problem-dependent parameters. Suppose you want to minimize the fitness given in the function myfit, subject to the nonlinear constraint myconstr, where these two functions are parameterized by their second argument a1 and a2, respectively. Here myfit and myconstr are M-file functions such as function f = myfit(x,a1) f = exp(x(1))*(4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + a1); and function [c,ceq] = myconstr(x,a2) c = [1.5 + x(1)*x(2) - x(1) - x(2); -x(1)*x(2) - a2]; % No nonlinear equality constraints: ceq = []; To optimize for specific values of a1 and a2, first assign the values to these two parameters. Then create two one-argument anonymous functions that capture the values of a1 and a2, and call myfit and myconstr with two arguments. Finally, pass these anonymous functions to GA: a1 = 1; a2 = 10; % define parameters first % Mutation function for constrained minimization options = gaoptimset('MutationFcn',@mutationadaptfeasible); x = ga(@(x)myfit(x,a1),2,[],[],[],[],[],[],@(x)myconstr(x,a2),options) |

7楼2013-11-21 17:05:00
8楼2013-11-22 12:17:46
LS1234567
新虫 (初入文坛)
- 应助: 0 (幼儿园)
- 金币: 181
- 帖子: 9
- 在线: 5.8小时
- 虫号: 2838577
- 注册: 2013-11-30
- 性别: MM
- 专业: 控制论中的数学方法
|
??? Undefined function or method 'myconstr' for input arguments of type 'double'. Error in ==> @(x)myconstr(x,a2) Error in ==> validate>@(x)nonlcon(x,NonconFcnArgs{:}) at 142 nonlcon = @(x) nonlcon(x,NonconFcnArgs{:}); Error in ==> constrValidate at 17 [cineq,ceq] = nonlcon(Iterate.x'); Error in ==> gacommon at 130 [LinearConstr, Iterate,nineqcstr,neqcstr,ncstr] = constrValidate(NonconFcn, ... Error in ==> ga at 267 [x,fval,exitFlag,output,population,scores,FitnessFcn,nvars,Aineq,bineq,Aeq,beq,lb,ub, ... Error in ==> Untitled at 6 x = ga(@(x)myfit(x,a1),2,[],[],[],[],[],[],@(x)myconstr(x,a2),options) Caused by: Failure in initial user-supplied nonlinear constraint function evaluation. 运行不了啊 |

9楼2015-05-14 11:08:58









回复此楼