批處理感知器算法的代碼matlab
w1=[1,0.1,1.1;1,6.8,7.1;1,-3.5,-4.1;1,2.0,2.7;1,4.1,2.8;1,3.1,5.0;1,-0.8,-1.3;
1,0.9,1.2;1,5.0,6.4;1,3.9,4.0];
w2=[1,7.1,4.2;1,-1.4,-4.3;1,4.5,0.0;1,6.3,1.6;1,4.2,1.9;1,1.4,-3.2;1,2.4,-4.0;
1,2.5,-6.1;1,8.4,3.7;1,4.1,-2.2];
w3=[1,-3.0,-2.9;1,0.5,8.7;1,2.9,2.1;1,-0.1,5.2;1,-4.0,2.2;1,-1.3,3.7;1,-3.4,6.2;
1,-4.1,3.4;1,-5.1,1.6;1,1.9,5.1];
figure;
Plot(w3(:,2),w3(:,3),'ro');
hold on;
Plot(w2(:,2),w2(:,3),'b+');
W=[w2;-w3];%增廣樣本規范化
a=[0,0,0];
k=0;%記錄步數
n=1;
y=zeros(size(W,2),1);%記錄錯分的樣本
while any(y<=0)
k=k+1;
y=a*transpose(W);%記錄錯分的樣本
a=a+sum(W(find(y<=0),:));%更新a
if k >= 250
break
end
end
if k<250
disp(['a為:',num2str(a)])
disp(['k為:',num2str(k)])
else
disp(['在250步以內沒有收斂,終止'])
end
%判決面:x2=-a2*x1/a3-a1/a3
xmin=min(min(w1(:,2)),min(w2(:,2)));
xmax=max(max(w1(:,2)),max(w2(:,2)));
x=xmin-1:xmax+1;%(xmax-xmin):
y=-a(2)*x/a(3)-a(1)/a(3);
Plot(x,y)
標簽:
批處理
算法matlab
上傳時間:
2016-11-07
上傳用戶:a1241314660
%球體
close all;
G=6.67e-11;
R=2;%球體半徑
p=4.0;%密度
D=10.0;%深度
M=(4/3)*pi*R^3*p;%質量
x=-20:1:20;
g=G*M*D./((x.^2+D^2).^(3/2));
Vxz=-3*G*M*D.*x./((x.^2+D^2).^(5/2));
Vzz=G*M.*(2*D^2-x.^2)./((x.^2+D^2).^(5/2));
Vzzz=3*G*M.*(2*D^2-3.*x.^2)./((x.^2+D^2).^(7/2));
subPlot(2,2,1)
Plot(x,g,'k-');
xlabel('水平距離(m)');
ylabel('重力異常值');
title('球體重力異常Δg');
grid on
subPlot(2,2,2)
Plot(x,Vxz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vxz');
grid on
subPlot(2,2,3)
Plot(x,Vzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzz');
grid on
subPlot(2,2,4);
Plot(x,Vzzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzzz');
grid on
%%
%水平圓柱體
close all
G=6.67e-11;
p=10.0;%線密度
D=100.0;%深度
x=-200:1:200;
g=G*2*p*D./(x.^2+D^2);
Vxz=4*G*p*D.*x./(x.^2+D^2).^2;
Vzz=2*G*p.*(D^2-x.^2)./(x.^2+D^2).^2;
Vzzz=4*G*p.*(D^2-3.*x.^2)./((x.^2+D^2).^3);
subPlot(2,2,1)
Plot(x,g,'k-');
xlabel('水平距離(m)');
ylabel('重力異常值');
title('水平圓柱體重力異常Δg');
grid on
subPlot(2,2,2)
Plot(x,Vxz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vxz');
grid on
subPlot(2,2,3)
Plot(x,Vzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzz');
grid on
subPlot(2,2,4);
Plot(x,Vzzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzzz');
grid on
%%
%垂直臺階
G=6.67e-11;
p=4.0;%密度
h1=50.0;%下層深度
h2=40.0;%上層深度
x=-100:1:100;
g=G*p.*(pi*(h1-h2)+x.*log((x.^2+h1^2)./(x.^2+h2^2))+2*h1.*atan(x./h1)-2*h2.*atan(x./h2));
Vxz=G*p.*log((h1^2+x.^2)./(h2^2+x.^2));
Vzz=2*G*p.*atan((x.*(h1-h2))./(x.^2+h1*h2));
Vzzz=2*G*p.*x*(h1^2-h2^2)./((h1^2+x.^2).*(x.^2+h2^2));
subPlot(2,2,1)
Plot(x,g,'k-');
xlabel('水平距離(m)');
ylabel('重力異常值');
title('垂直臺階重力異常Δg');
grid on
subPlot(2,2,2)
Plot(x,Vxz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vxz');
grid on
subPlot(2,2,3)
Plot(x,Vzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzz');
grid on
subPlot(2,2,4);
Plot(x,Vzzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzzz');
grid on
%%
%傾斜臺階
G=6.67e-11;
p=4.0;%密度
h1=50.0;%下層深度
h2=40.0;%上層深度
a=pi/6;%傾斜角度
x=-500:1:500;
g=G*p.*(pi*(h1-h2)+2*h1.*atan((x+h1*cot(a))./h1)-2*h2.*atan((x+h2*cot(a))./h1)+x.*sin(a)^2.*log(((h1+x.*sin(a).*cos(a)).^2+x.^2.*sin(a)^4)./((h2+x.*(sin(a)*cos(a))).^2+x.^2.*sin(a)^4)));
Vxz=G*p.*(sin(a)^2.*log(((h1*cot(a)+x).^2+h1^2)./((h2*cot(a)+x).^2+h2^2))-2*sin(2*a).*(atan((h1/sin(a)+x.*cos(a))./(x.*sin(a)))-atan((h2/sin(a)+x.^cos(a))./(sin(a).*x))));
Vzz=G*p.*(0.5*sin(2*a)^2.*log(((h1*cot(a)+x).^2+h1^2)./((h2*cot(a)+x).^2+h2^2))+2*sin(a)^2.*(atan((h1/sin(a)+x.*cos(a))./(x.*sin(a)))-atan((h2/sin(a)+x.*cos(a))./(x.*sin(a)))));
Vzzz=2*G*p*sin(a)^2.*((x+2*h2*cot(a))./((h2*cot(a)+x).^2+h2^2)-(x+2*h1*cot(a))./((h1*cot(a)+x).^2+h1^2));
subPlot(2,2,1)
Plot(x,g,'k-');
xlabel('水平距離(m)');
ylabel('重力異常值');
title('傾斜臺階重力異常Δg');
grid on
subPlot(2,2,2)
Plot(x,Vxz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vxz');
grid on
subPlot(2,2,3)
Plot(x,Vzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzz');
grid on
subPlot(2,2,4);
Plot(x,Vzzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzzz');
grid on
%%
%鉛錘柱體
G=6.67e-11;
p=4.0;%密度
h1=50.0;%下層深度
h2=40.0;%上層深度
a=3;%半徑
x=-500:1:500;
g=G*p.*((x+a).*log(((x+a).^2+h1^2)./((x+a).^2+h2^2))-(x-a).*log(((x-a).^2+h1^2)./((x-a).^2+h2^2))+2*h1.*(atan((x+a)./h1)-atan((x-a)./h1))-2*h2.*(atan((x+a)./h2)-atan((x-a)./h2)));
Vxz=G*p.*log((((x+a).^2+h1^2).*((x-a).^2+h2^2))./(((x+a).^2+h2^2).*((x-a).^2+h1^2)));
Vzz=2*G*p.*(atan(h1./(x+a))-atan(h2./(x+a))-atan(h1./(x-a))+atan(h2./(x-a)));
Vzzz=2*G*p.*((x+a)./((x+a).^2+h2^2)-(x+a)./((x+a).^2+h1^2)-(x-a)./((x-a).^2+h2^2)+(x-a)./((x-a).^2+h1^2));
subPlot(2,2,1)
Plot(x,g,'k-');
xlabel('水平距離/m')
ylabel('重力異常值')
title('鉛垂柱體重力異常')
grid on
subPlot(2,2,2)
Plot(x,Vxz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vxz');
grid on
subPlot(2,2,3)
Plot(x,Vzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzz');
grid on
subPlot(2,2,4);
Plot(x,Vzzz);
xlabel('水平距離(m)');
ylabel('導數值');
title('Vzzz');
grid on
標簽:
MATLAB
重力
正
程序
上傳時間:
2019-05-10
上傳用戶:xiajiang