初学matlab 一个小程序,折磨我一天了,也不知道应该怎么改.
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/19 00:59:52
初学matlab 一个小程序,折磨我一天了,也不知道应该怎么改.
主程序:
clear all;clc
syms C1 C2 C3
x=[C1 C2 C3];
for i=1:5
Y(i)=1*C1*i+2*C2*i+3*C3*i;
end
Y1=Y';
b=[4;5;6;7;8];
yo=Y1-b;
options=gaoptimset('PopulationSize',500,'Generations',1000,'StallGenLimit',1000,'TolFun',1e-1000);
[x,fval]=ga(@(x)ga_equation_group(x,yo),3,options)
自定义函数:
function f=ga_equation_group(x,yo)
n=length(yo);
for i=1:n
d(i)=yo(i);
end
f=sum(d.^2);
The following error occurred converting from sym to double:
Error using ==> mupadmex
Error in MuPAD command:DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable,use the VPA function instead.
Error in ==> fcnvectorizer at 14
y(i,:) = feval(fun,(pop(i,:)));
Error in ==> makeState at 47
Score =
fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in ==> gaunc at 41
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 291
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars,...
Error in ==> bianjiayichuan at 14
[x,fval]=ga(@(x)ga_equation_group(x,yo),3,options)
Caused by:
Failure in user-supplied fitness function evaluation.GA cannot continue.
错误
一堆啊,哪位英雄救救我吧
主程序:
clear all;clc
syms C1 C2 C3
x=[C1 C2 C3];
for i=1:5
Y(i)=1*C1*i+2*C2*i+3*C3*i;
end
Y1=Y';
b=[4;5;6;7;8];
yo=Y1-b;
options=gaoptimset('PopulationSize',500,'Generations',1000,'StallGenLimit',1000,'TolFun',1e-1000);
[x,fval]=ga(@(x)ga_equation_group(x,yo),3,options)
自定义函数:
function f=ga_equation_group(x,yo)
n=length(yo);
for i=1:n
d(i)=yo(i);
end
f=sum(d.^2);
The following error occurred converting from sym to double:
Error using ==> mupadmex
Error in MuPAD command:DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable,use the VPA function instead.
Error in ==> fcnvectorizer at 14
y(i,:) = feval(fun,(pop(i,:)));
Error in ==> makeState at 47
Score =
fcnvectorizer(state.Population(initScoreProvided+1:end,:),FitnessFcn,1,options.SerialUserFcn);
Error in ==> gaunc at 41
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ==> ga at 291
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars,...
Error in ==> bianjiayichuan at 14
[x,fval]=ga(@(x)ga_equation_group(x,yo),3,options)
Caused by:
Failure in user-supplied fitness function evaluation.GA cannot continue.
错误
一堆啊,哪位英雄救救我吧
你这代码写的乱七八糟的,不知道你要干嘛
你把你要做的规划写出来,不方便写就截图
再问: 就是要编一个解非线性方程组的遗传算法程序 超定方程 我只是实验找点简单的数 可是还是一堆错误
再答: function f=fun(x) y=1:5; y=([x(1) x(2) x(3)]*[y;2*y;3*y])'-y'-3; f=sum(y.^2); %%%%%%%%%%%%%%%% 主程序 clear all;clc [x,val]=ga(@fun,3) 其实这种问题一般不用遗传算法
你把你要做的规划写出来,不方便写就截图
再问: 就是要编一个解非线性方程组的遗传算法程序 超定方程 我只是实验找点简单的数 可是还是一堆错误
再答: function f=fun(x) y=1:5; y=([x(1) x(2) x(3)]*[y;2*y;3*y])'-y'-3; f=sum(y.^2); %%%%%%%%%%%%%%%% 主程序 clear all;clc [x,val]=ga(@fun,3) 其实这种问题一般不用遗传算法