📄 newsolver1.m
字号:
%函数(2):在x1的领域产生一组新的解
%newSolver1根据x1的误差给出一个新的可能解x
function x2=newSolver1(x1,x1Error,leftBound,distance,rightBound)
%parameter=[leftBound,distance,rightBound]
%leftBound:解空间的左边界,distance:可能解的间隔,rightBound:解空间的右边界
%解空间是指在一个坐标轴上解的左右边界和解之间的间隔
[x1Group,x1N]=size(x1);
%x1Group:x1的行数,x1N:方程的元数
%round((-0.5+rand(x1Group,x1N))*2)
if x1Error<=30%在解空间上移动1格
x2=x1+round((-0.5+rand(x1Group,x1N))*2)*distance;
k=x2<leftBound;%防止新解越过左边界
x2(:,k)=leftBound;
k=x2>rightBound;%防止新解越过右边界
x2(:,k)=rightBound;
elseif x1Error>30 && x1Error<=100%在解空间上移动3格以下
x2=x1+round((-0.5+rand(x1Group,x1N))*6)*distance;
k=x2<leftBound;
x2(:,k)=leftBound;
k=x2>rightBound;
x2(:,k)=rightBound;
elseif x1Error>100 && x1Error<=1000%在解空间上移动9格以下
x2=x1+round((-0.5+rand(x1Group,x1N))*20)*distance;
k=x2<leftBound;
x2(:,k)=leftBound;
k=x2>rightBound;
x2(:,k)=rightBound;
elseif x1Error>1000 && x1Error<=10000%在解空间上移动20格以下
x2=x1+round((-0.5+rand(x1Group,x1N))*40)*distance;
k=x2<leftBound;
x2(:,k)=leftBound;
k=x2>rightBound;
x2(:,k)=rightBound;
elseif x1Error>10000%在解空间上移动30格以下
x2=x1+round((-0.5+rand(x1Group,x1N))*60)*distance;
k=x2<leftBound;
x2(:,k)=leftBound;
k=x2>rightBound;
x2(:,k)=rightBound;
end
if x1==x2
x2=round((-0.5+rand(x1Group,x1N))*20);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -