全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
3116 6
2011-08-03
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.
-----------------------------
本人做了一个遗传优化方面的,结果出现上面的提示,什么意思啊,
二维码

扫码加我 拉你入群

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

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

全部回复
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
二维码

扫码加我 拉你入群

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

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

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=[];
二维码

扫码加我 拉你入群

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

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

2011-8-3 22:19:17
感谢了,期待你的解答
二维码

扫码加我 拉你入群

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

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

2014-1-5 19:40:02
先mark一下,等等再看
二维码

扫码加我 拉你入群

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

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

2014-1-5 20:00:41
sym.double at 25
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群