求指教,PSO算法跟踪光伏电池最大功率点

底下是粒子群算法代码和子程序:
%------初始格式化--------------------------------------------------
clear all;
clc;
format long;
%------给定初始化条件---------------------------------------------
c1=2; %学习因子1
c2=2; %学习因子2
w_max=0.9;
w_min=0.4; %惯性权重
MaxDT=50; %最大迭代次数
D=2; %搜索空间维数
N=20; %初始化群体个体数目
Vmax=2;
Vmin=0;
popmax=40;
popmin=0;
%----初始化种群的个体-----------
for i=1:N
pop(i,:)=popmin+(popmax-popmin)randn(1,2);%随机初始化位置
V(i,:)=randn(1,2); %随机初始化速度
fitness(i)=ackley(pop(i,:));
end
%------计算各个粒子的适应度,并初始化Pi和Pg----------------------
[fitnessgbest bestindex]=max(fitness);
gbest=pop(bestindex,:);
pbest=pop;
fitnesspbest=fitness;
for i=1:MaxDT
for j=1:N
w=w_max-(w_max-w_min)i/MaxDT; %惯性权重线性调整
V(j,:)=w
V(j,:)+c1
rand*(pbest(j,:)-pop(j,:))+c2rand(gbest-pop(j,:));
V(j,find(V(j,:)>Vmax))=Vmax;
V(j,find(V(j,:)<Vmin))=Vmin; %速度更新
pop(j,:)=pop(j,:)+V(j,:);
pop(j,find(pop(j,:)>popmax))=popmax;
pop(j,find(pop(j,:)<popmin))=popmin; %位置更新
if rand>0.8
k=ceil(2rand);
pop(j,k)=rand;
end
fitness(j)=ackley(pop(j,:));
if fitness(j)>fitnesspbest(j) %局部最优
pbest(j,:)=pop(j,:);
fitnesspbest(j)=fitness(j);
end
if fitness(j)>fitnessgbest %全局最优
gbest=pop(j,:);
fitnessgbest=fitness(j);
end
end
yy(i)=fitnessgbest;
end
%------最后给出计算结果---------------
plot(yy)
title(['适应度曲线 ’ ‘终止次数=’ num2str(MaxDT)]);
xlabel(‘进化代数’);
ylabel(‘输出功率P(w)’)
disp('
’)
disp(‘光伏系统全局最优电压为:’)
Um=gbest(2)
disp(‘光伏系统全局最大输出功率为:’)
Pm=fitnessgbest
disp('
*’)
%------算法结束--------------------------------------

子程序:
function [out]=ackley(in)
[ t, x, P ] = sim( ‘twopvs’, [0:1:2],[], in); %调用光伏阵列Simulink模块
out=max§; %输出功率
return,

两块光伏电池simulink搭建模型
求指教,PSO算法跟踪光伏电池最大功率点
运行结果出现以下情况,请问各位这是哪里出现错误了呢,感谢!
求指教,PSO算法跟踪光伏电池最大功率点