楼主: wchampion
2905 6

[问答] 遗传算法-matlab-优化 [推广有奖]

  • 0关注
  • 0粉丝

本科生

6%

还不是VIP/贵宾

-

威望
0
论坛币
236 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
3783 点
帖子
81
精华
0
在线时间
41 小时
注册时间
2009-11-19
最后登录
2022-12-20

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
running.
Error using ==> constrValidate at 23
Cannot continue because user supplied constraint function failed with the following error:
The following error occurred converting from sym to double:
Error using ==> sym.double at 25
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
-----------------------------
本人做了一个遗传优化方面的,结果出现上面的提示,什么意思啊,
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:MATLAB matla atlab 遗传算法 Lab expression following function continue occurred

沙发
wchampion 发表于 2011-8-3 22:10:53 |只看作者 |坛友微信交流群
function fun = trefun(x)
a=[1 0 0;-1 0 0;1 -1 0;0 1 -1;0 0 1;0 0 1];
A0=[-1 0 0 0;0 1 0 0;0 0 0 0;0 0 0 0;0 0 -1 0;0 0 0 -1];
H=[35.418;45.712;25.270;24.678];
a0=A0*H;
y=[8.228;-2.060;-1.515;7.477;12.417;13.000];

%定义参数
digits(8);
cc=0;
f=0;
syms x1 x2 x3 x4 x5 x6 x7 x8 x9   %定义符号变量
deta=sym([x1;x2;x3;x4;x5;x6])      %定义符号数组
xx=sym([x7;x8;x9])
for i=1:6
    for j=1:3
        c=a(i,j).* xx(j);
        cc=cc+c;
    end
    cc;
    mm=abs(y(i)-a0(i)-cc);
    ff=1+deta(i)-mm./deta(i);
    f=f+ff;
end
fun=f

使用道具

藤椅
wchampion 发表于 2011-8-3 22:18:33 |只看作者 |坛友微信交流群
上面是适应函数,下面是非线性约束
function [ c,ceq] = tre_constraint(x)
a=[1 0 0;-1 0 0;1 -1 0;0 1 -1;0 0 1;0 0 1];
A0=[-1 0 0 0;0 1 0 0;0 0 0 0;0 0 0 0;0 0 -1 0;0 0 0 -1];
H=[35.418;45.712;25.270;24.678];
a0=A0*H;
y=[8.228;-2.060;-1.515;7.477;12.417;13.000];

%定义参数
cc=0;
f=0;
syms x1 x2 x3 x4 x5 x6 x7 x8 x9   %定义符号变量
deta=sym([x1;x2;x3;x4;x5;x6])      %定义符号数组
xx=sym([x7;x8;x9])
for i=1:6
    for j=1:3
        c=a(i,j).* xx(j);
        cc=cc+c;
    end
    cc;
    mm=vpa(abs(y(i)-a0(i)-cc));
    cceq(i)=mm-deta(i);
end
c=cceq.';
ceq=[];

使用道具

板凳
wchampion 发表于 2011-8-3 22:19:17 |只看作者 |坛友微信交流群
感谢了,期待你的解答

使用道具

报纸
zhangibt 发表于 2014-1-5 19:40:02 |只看作者 |坛友微信交流群
先mark一下,等等再看

使用道具

地板
zym9456 发表于 2014-1-5 20:00:41 |只看作者 |坛友微信交流群
sym.double at 25

使用道具

7
zym9456 发表于 2014-1-5 20:01:46 |只看作者 |坛友微信交流群
use the VPA function instead.

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-13 03:43