初学matlab 一个小程序,折磨我一天了,也不知道应该怎么改.主程序:clear all;clcsyms C1 C2 C3x=[C1 C2 C3];for i=1:5Y(i)=1*C1*i+2*C2*i+3*C3*i;endY1=Y';b=[4;5;6;7;8];yo=Y1-b;options=gaoptimset('PopulationSize',500,'Generations',100
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/06 06:02:13
初学matlab 一个小程序,折磨我一天了,也不知道应该怎么改.主程序:clear all;clcsyms C1 C2 C3x=[C1 C2 C3];for i=1:5Y(i)=1*C1*i+2*C2*i+3*C3*i;endY1=Y';b=[4;5;6;7;8];yo=Y1-b;options=gaoptimset('PopulationSize',500,'Generations',100
初学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.
错误
一堆啊,哪位英雄救救我吧
初学matlab 一个小程序,折磨我一天了,也不知道应该怎么改.主程序:clear all;clcsyms C1 C2 C3x=[C1 C2 C3];for i=1:5Y(i)=1*C1*i+2*C2*i+3*C3*i;endY1=Y';b=[4;5;6;7;8];yo=Y1-b;options=gaoptimset('PopulationSize',500,'Generations',100
你这代码写的乱七八糟的,不知道你要干嘛
你把你要做的规划写出来,不方便写就截图