Why doesn't my simple PSO work?
显示 更早的评论
Hi!
I tried to run the following code but I am getting constantly errors:
clear all
clc
g = @(V)-( 6.3223*V(4)^2 + 18*V(4) + 12.812 )/V(4);
PID = @(V)V(1) + V(2)/V(4) + V(3)*V(4);
entrada = @(V)heaviside(V(4));
H = @(V)PID(V)*g(V);
erro = @(V)entrada(V)/(H(V) + 1);
ITAE = @(V)integral(abs(erro(V))*V(4),0,inf);
nvar = 4;
rng default
options = optimoptions('particleswarm','SwarmSize',100,'MaxIterations',100);
lb = [0 0 0 -inf];
ub = [100 100 100 inf];
[x,fval] = particleswarm(ITAE, nvar,lb ,ub, options);
The error says that the first argument should be a function handle. I verified the datatype using the command 'whos' and it says it's a fucntion handle!! What I am doing wrong?
3 个评论
Jorge Guerra Pires
2017-1-31
Dear Daniel Caliari, you code seems correct, I cannot see the problem. What I would do in your position is eliminating the function handling notation, create a m-file function for each function you need; it might happen that overlapping the function handling as you did created a bug problem, it is just a possibility. I have worked with PSO with m-files, not function handling, and the examples I have seen used just one function handling. Try it, it might be a possibility.
John D'Errico
2017-1-31
Jorge - no, the problem is not in pso, or in the use of function handles that call function handles. The problem is improperly calling integral.
Jorge Guerra Pires
2017-1-31
John D'Errico, you are right, integral is not a created function, rather an built in function; supposing it is the case. Hopefully that solves the problem!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Particle Swarm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!