Matlab仿真偶极子天线激励

%文件描述:三维偶极子源激励,PML吸收边界,采用矩阵赋值
%激励描述:高斯脉冲
%激励位置:空间中心位置
%介质描述:自由空间

clear all;close all;clc;

%设置初始条件
NSTEPS=80;%时间步
IE=40;JE=40;KE=40;%仿真空间大小
ic=IE/2;jc=JE/2;kc=KE/2;%观察点位置
ra_y=1.0;ra_x=1.0;%方向比例系数
nx=IE;ny=JE;nz=KE;

%PML边界空间大小
ia=7;ib=IE-ia-1;
ja=7;jb=JE-ja-1;
ka=7;kb=KE-ka-1;

epsz=8.85419e-12;%真空中的介电常数
muz=4*pi*1e-7;%真空中的磁导率
c0=3e8;%自由空间中的光速
ddx=0.01;%空间步长,单个波长中取20个网格
dt=ddx/(2*c0);%时间步长
t0=20;spread=6;%高斯脉冲参数

%场量初始化
gax=ones(IE,JE,KE);gay=gax;gaz=gax;
gbx=zeros(IE,JE,KE);gby=gbx;gbz=gbx;
disp_x=zeros(IE,JE,KE);disp_y=disp_x;disp_z=disp_x;
ex=zeros(IE,JE,KE);ey=ex;ez=ex;
ix=zeros(IE,JE,KE);iy=ix;iz=ix;
hx=zeros(IE,JE,KE);hy=hx;hz=hx;
curl_h=zeros(IE,JE,KE);curl_e=zeros(IE,JE,KE);
idxl=zeros(IE,JE,KE);idyl=idxl;idzl=idxl;
idxh=zeros(IE,JE,KE);idyh=idxh;idzh=idxh;
ihxl=zeros(IE,JE,KE);ihyl=ihxl;ihzl=ihxl;
ihxh=zeros(IE,JE,KE);ihyh=ihxh;ihzh=ihxh;

ez_inc(1:JE)=0.0;hx_inc(1:JE)=0.0;
ez_inc_low_m1=0.0;ez_inc_low_m2=0.0;
ez_inc_high_m1=0.0;ez_inc_hgh_m2=0.0;
gi1(1:IE)=0.0;gi2(1:IE)=1.0;gi3(1:IE)=1.0;
gj1(1:JE)=0.0;gj2(1:JE)=1.0;gj3(1:JE)=1.0;
gk1(1:KE)=0.0;gk2(1:KE)=1.0;gk3(1:KE)=1.0;
fi1(1:IE)=0.0;fi2(1:IE)=1.0;fi3(1:IE)=1.0;
fj1(1:JE)=0.0;fj2(1:JE)=1.0;fj3(1:JE)=1.0;
fk1(1:KE)=0.0;fk2(1:KE)=1.0;fk3(1:KE)=1.0;

%设置dipole位置
gaz(ic,jc,12:30)=0;
gaz(ic,jc,kc)=1;

%PML边界设置
npml=7;
i=1:npml;
xxn=(npml-i+1)/npml;
xn1=0.33*(xxn.^3);
xn(1:nx)=1.0;
xn(1:npml)=xn1;
xn(nx-npml+1:nx)=xn1(end:-1:1);
fi1(1:npml)=xn(1:npml);
fi1(nx-npml+1:nx)=xn(nx-npml+1:nx);
gi2(1:npml)=1.0./(1.0+xn(1:npml));
gi2(nx-npml+1:nx)=1.0./(1.0+xn(nx-npml+1:nx));
gi3(1:npml)=(1.0-xn(1:npml))./(1.0+xn(1:npml));
gi3(nx-npml+1:nx)=(1.0-xn(nx-npml+1:nx))./(1.0+xn(nx-npml+1:nx));

xxn=(npml-i-0.5+1)/npml;
xn1=0.33*(xxn.^3);
xn(nx)=1.0;
xn(1:npml)=xn1;
xn(nx-npml:nx-1)=xn1(end:-1:1);
gi1(1:npml)=xn(1:npml);
gi1(nx-npml:nx-1)=xn(nx-npml:nx-1);
fi2(1:npml)=1.0./(1.0+xn(1:npml));
fi2(nx-npml:nx-1)=1.0./(1.0+xn(nx-npml:nx-1));
fi3(1:npml)=(1.0-xn(1:npml))./(1.0+xn(1:npml));
fi3(nx-npml:nx-1)=(1.0-xn(nx-npml:nx-1))./(1.0+xn(nx-npml:nx-1));

j=1:npml;
xxn=(npml-j+1)/npml;
xn1=0.33*(xxn.^3);
xn(ny)=1.0;
xn(1:npml)=xn1;
xn(ny-npml+1:ny)=xn1(end:-1:1);
fj1(1:npml)=xn(1:npml);
fj1(ny-npml+1:nx)=xn(ny-npml+1:ny);
gj2(1:npml)=1.0./(1.0+xn(1:npml));
gj2(ny-npml+1:ny)=1.0./(1.0+xn(ny-npml+1:ny));
gj3(1:npml)=(1.0-xn(1:npml))./(1.0+xn(1:npml));
gj3(ny-npml+1:nx)=(1.0-xn(ny-npml+1:ny))./(1.0+xn(ny-npml+1:ny));

xxn=(npml-j-0.5+1)/npml;
xn1=0.33*(xxn.^3);
xn(ny)=1.0;
xn(1:npml)=xn1;
xn(ny-npml:ny-1)=xn1(end:-1:1);
gj1(1:npml)=xn(1:npml);
gj1(ny-npml:ny-1)=xn(ny-npml:ny-1);
fj2(1:npml)=1.0./(1.0+xn(1:npml));
fj2(ny-npml:ny-1)=1.0./(1.0+xn(ny-npml:ny-1));
fj3(1:npml)=(1.0-xn(1:npml))./(1.0+xn(1:npml));
fj3(ny-npml:ny-1)=(1.0-xn(ny-npml:ny-1))./(1.0+xn(ny-npml:ny-1));

k=1:npml;
xxn=(npml-k+1)/npml;
xn1=0.33*(xxn.^3);
xn(nz)=1.0;
xn(1:npml)=xn1;
xn(nz-npml+1:nz)=xn1(end:-1:1);
fk1(1:npml)=xn(1:npml);
fk1(nz-npml+1:nz)=xn(nz-npml+1:nz);
gk2(1:npml)=1.0./(1.0+xn(1:npml));
gk2(nz-npml+1:nz)=1.0./(1.0+xn(nz-npml+1:nz));
gk3(1:npml)=(1.0-xn(1:npml))./(1.0+xn(1:npml));
gk3(nz-npml+1:nz)=(1.0-xn(nz-npml+1:nz))./(1.0+xn(nz-npml+1:nz));

xxn=(npml-k-0.5+1)/npml;
xn1=0.33*(xxn.^3);
xn(nz)=1.0;
xn(1:npml)=xn1;
xn(nz-npml:nz-1)=xn1(end:-1:1);
gk1(1:npml)=xn(1:npml);
gk1(nz-npml:nz-1)=xn(nz-npml:nz-1);
fk2(1:npml)=1.0./(1.0+xn(1:npml));
fk2(nz-npml:nz-1)=1.0./(1.0+xn(nz-npml:nz-1));
fk3(1:npml)=(1.0-xn(1:npml))./(1.0+xn(1:npml));
fk3(nz-npml:nz-1)=(1.0-xn(nz-npml:nz-1))./(1.0+xn(nz-npml:nz-1));

%数组变换

gj1_3w=repmat(gj1,[IE 1 KE]);
gj2_3w=repmat(gj2,[IE 1 KE]);
gj3_3w=repmat(gj3,[IE 1 KE]);
gk1_3w=shiftdim(repmat(gk1,[JE 1 IE]),2);
gk2_3w=shiftdim(repmat(gk2,[JE 1 IE]),2);
gk3_3w=shiftdim(repmat(gk3,[JE 1 IE]),2);
gi1_3w=shiftdim(repmat(gi1,[KE 1 IE]),1);
gi2_3w=shiftdim(repmat(gi2,[KE 1 IE]),1);
gi3_3w=shiftdim(repmat(gi3,[KE 1 IE]),1);

fj1_3w=repmat(fj1,[IE 1 KE]);
fj2_3w=repmat(fj2,[IE 1 KE]);
fj3_3w=repmat(fj3,[IE 1 KE]);
fk1_3w=shiftdim(repmat(fk1,[JE 1 IE]),2);
fk2_3w=shiftdim(repmat(fk2,[JE 1 IE]),2);
fk3_3w=shiftdim(repmat(fk3,[JE 1 IE]),2);
fi1_3w=shiftdim(repmat(fi1,[KE 1 IE]),1);
fi2_3w=shiftdim(repmat(fi2,[KE 1 IE]),1);
fi3_3w=shiftdim(repmat(fi3,[KE 1 IE]),1);

for n=1:NSTEPS
    %计算dx

    curl_h(2:ia,2:ny,2:nz)=(ra_y*(hz(2:ia,2:ny,2:nz)...
        -hz(2:ia,1:ny-1,2:nz))-hy(2:ia,2:ny,2:nz)+hy(2:ia,2:ny,1:nz-1));
    idxl(2:ia,2:ny,2:nz)=idxl(2:ia,2:ny,2:nz)+curl_h(2:ia,2:ny,2:nz);
    disp_x(2:ia,2:ny,2:nz)=gj3_3w(2:ia,2:ny,2:nz)...
        .*gk3_3w(2:ia,2:ny,2:nz).*disp_x(2:ia,2:ny,2:nz)+...
        gj2_3w(2:ia,2:ny,2:nz).*gk2_3w(2:ia,2:ny,2:nz)*0.5...
        .*(curl_h(2:ia,2:ny,2:nz)+gi1_3w(2:ia,2:ny,2:nz)...
        .*idxl(2:ia,2:ny,2:nz));

    curl_h(ia+1:ib+1,2:ny,2:nz)=(ra_y*(hz(ia+1:ib+1,2:ny,2:nz)...
        -hz(ia+1:ib+1,1:ny-1,2:nz))-hy(ia+1:ib+1,2:ny,2:nz)...
        +hy(ia+1:ib+1,2:ny,1:nz-1));
    disp_x(ia+1:ib+1,2:ny,2:nz)=gj3_3w(ia+1:ib+1,2:ny,2:nz)...
        .*gk3_3w(ia+1:ib+1,2:ny,2:nz).*disp_x(ia+1:ib+1,2:ny,2:nz)+...
        gj2_3w(ia+1:ib+1,2:ny,2:nz).*gk2_3w(ia+1:ib+1,2:ny,2:nz)...
        *0.5.*curl_h(ia+1:ib+1,2:ny,2:nz);

    curl_h(ib+2:nx,2:ny,2:nz)=(ra_y*(hz(ib+2:nx,2:ny,2:nz)...
        -hz(ib+2:nx,1:ny-1,2:nz))-hy(ib+2:nx,2:ny,2:nz)...
        +hy(ib+2:nx,2:ny,1:nz-1));
    idxh(1:ia,2:ny,2:nz)=idxh(1:ia,2:ny,2:nz)+curl_h(ib+2:nx,2:ny,2:nz);
    disp_x(ib+2:nx,2:ny,2:nz)=gj3_3w(ib+2:nx,2:ny,2:nz)...
        .*gk3_3w(ib+2:nx,2:ny,2:nz).*disp_x(ib+2:nx,2:ny,2:nz)+...
        gj2_3w(ib+2:nx,2:ny,2:nz).*gk2_3w(ib+2:nx,2:ny,2:nz)*0.5...
        .*(curl_h(ib+2:nx,2:ny,2:nz)+gi1_3w(ib+2:nx,2:ny,2:nz)...
        .*idxl(1:ia,2:ny,2:nz));

    %计算dy

    curl_h(2:nx,2:ja,2:nz)=(-ra_x*(hz(2:nx,2:ja,2:nz)...
        -hz(1:nx-1,2:ja,2:nz))+hx(2:nx,2:ja,2:nz)-hx(2:nx,2:ja,1:nz-1));
    idyl(2:nx,2:ja,2:nz)=idyl(2:nx,2:ja,2:nz)+curl_h(2:nx,2:ja,2:nz);
    disp_y(2:nx,2:ja,2:nz)=gi3_3w(2:nx,2:ja,2:nz)...
        .*gk3_3w(2:nx,2:ja,2:nz).*disp_y(2:nx,2:ja,2:nz)+...
        gi2_3w(2:nx,2:ja,2:nz).*gk2_3w(2:nx,2:ja,2:nz)*0.5...
        .*(curl_h(2:nx,2:ja,2:nz)+gj1_3w(2:nx,2:ja,2:nz)...
        .*idyl(2:nx,2:ja,2:nz));

    curl_h(2:nx,ja+1:jb+1,2:nz)=(-ra_x*(hz(2:nx,ja+1:jb+1,2:nz)...
        -hz(1:nx-1,ja+1:jb+1,2:nz))+hx(2:nx,ja+1:jb+1,2:nz)...
        -hx(2:nx,ja+1:jb+1,1:nz-1));
    disp_y(2:nx,ja+1:jb+1,2:nz)=gi3_3w(2:nx,ja+1:jb+1,2:nz)...
        .*gk3_3w(2:nx,ja+1:jb+1,2:nz).*disp_y(2:nx,ja+1:jb+1,2:nz)+...
        gi2_3w(2:nx,ja+1:jb+1,2:nz).*gk2_3w(2:nx,ja+1:jb+1,2:nz)...
        *0.5.*curl_h(2:nx,ja+1:jb+1,2:nz);

    curl_h(2:nx,jb+2:ny,2:nz)=(-ra_x*(hz(2:nx,jb+2:ny,2:nz)...
        -hz(1:nx-1,jb+2:ny,2:nz))+hx(2:nx,jb+2:ny,2:nz)...
        -hx(2:nx,jb+2:ny,1:nz-1));
    idyh(2:nx,1:ja,2:nz)=idyh(2:nx,1:ja,2:nz)+curl_h(2:nx,jb+2:ny,2:nz);
    disp_y(2:nx,jb+2:ny,2:nz)=gi3_3w(2:nx,jb+2:ny,2:nz)...
        .*gk3_3w(2:nx,jb+2:ny,2:nz).*disp_y(2:nx,jb+2:ny,2:nz)+...
        gi2_3w(2:nx,jb+2:ny,2:nz).*gk2_3w(2:nx,jb+2:ny,2:nz)*0.5...
        .*(curl_h(2:nx,jb+2:ny,2:nz)+gj1_3w(2:nx,jb+2:ny,2:nz)...
        .*idyh(2:nx,1:ja,2:nz));

    %计算dz

    curl_h(2:nx,2:ny,1:ka)=(ra_x*(hy(2:nx,2:ny,1:ka)...
        -hy(1:nx-1,2:ny,1:ka))-ra_y*(hx(2:nx,2:ny,1:ka)-hx(2:nx,1:ny-1,1:ka)));
    idzl(2:nx,2:ny,1:ka)=idzl(2:nx,2:ny,1:ka)+curl_h(2:nx,2:ny,1:ka);
    disp_z(2:nx,2:ny,1:ka)=gi3_3w(2:nx,2:ny,1:ka)...
        .*gj3_3w(2:nx,2:ny,1:ka).*disp_z(2:nx,2:ny,1:ka)+...
        gi2_3w(2:nx,2:ny,1:ka).*gj2_3w(2:nx,2:ny,1:ka)*0.5...
        .*(curl_h(2:nx,2:ny,1:ka)+gk1_3w(2:nx,2:ny,1:ka)...
        .*idzl(2:nx,2:ny,1:ka));

    curl_h(2:nx,2:ny,ka+1:kb+1)=(ra_x*(hy(2:nx,2:ny,ka+1:kb+1)...
        -hy(1:nx-1,2:ny,ka+1:kb+1))-ra_y*(hx(2:nx,2:ny,ka+1:kb+1)...
        -hx(2:nx,1:ny-1,ka+1:kb+1)));
    disp_z(2:nx,2:ny,ka+1:kb+1)=gi3_3w(2:nx,2:ny,ka+1:kb+1)...
        .*gj3_3w(2:nx,2:ny,ka+1:kb+1).*disp_z(2:nx,2:ny,ka+1:kb+1)+...
        gi2_3w(2:nx,2:ny,ka+1:kb+1).*gj2_3w(2:nx,2:ny,ka+1:kb+1)...
        *0.5.*curl_h(2:nx,2:ny,ka+1:kb+1);

    curl_h(2:nx,2:ny,kb+2:nz)=(ra_x*(hy(2:nx,2:ny,kb+2:nz)...
        -hy(1:nx-1,2:ny,kb+2:nz))-ra_y*(hx(2:nx,2:ny,kb+2:nz)...
        -hx(2:nx,1:ny-1,kb+2:nz)));
    idzh(2:nx,2:ny,1:ka)=idzh(2:nx,2:ny,1:ka)+curl_h(2:nx,2:ny,kb+2:nz);
    disp_z(2:nx,2:ny,kb+2:nz)=gi3_3w(2:nx,2:ny,kb+2:nz)...
        .*gj3_3w(2:nx,2:ny,kb+2:nz).*disp_z(2:nx,2:ny,kb+2:nz)+...
        gi2_3w(2:nx,2:ny,kb+2:nz).*gj2_3w(2:nx,2:ny,kb+2:nz)*0.5...
        .*(curl_h(2:nx,2:ny,kb+2:nz)+gk1_3w(2:nx,2:ny,kb+2:nz)...
        .*idzh(2:nx,2:ny,1:ka));

    %加入激励源
    pulse=exp(-0.5*((t0-n)/spread)^2);
    disp_z(ic,jc,kc)=pulse;
    
    %计算ex,ey,ez
    ex(2:IE-1,2:JE-1,2:KE-1)=gax(2:IE-1,2:JE-1,2:KE-1)...
        .*(disp_x(2:IE-1,2:JE-1,2:KE-1)-ix(2:IE-1,2:JE-1,2:KE-1));
    ix(2:IE-1,2:JE-1,2:KE-1)=ix(2:IE-1,2:JE-1,2:KE-1)...
        +gbx(2:IE-1,2:JE-1,2:KE-1).*ex(2:IE-1,2:JE-1,2:KE-1);
    ey(2:IE-1,2:JE-1,2:KE-1)=gay(2:IE-1,2:JE-1,2:KE-1)...
        .*(disp_y(2:IE-1,2:JE-1,2:KE-1)-iy(2:IE-1,2:JE-1,2:KE-1));
    iy(2:IE-1,2:JE-1,2:KE-1)=iy(2:IE-1,2:JE-1,2:KE-1)...
        +gby(2:IE-1,2:JE-1,2:KE-1).*ey(2:IE-1,2:JE-1,2:KE-1);
    ez(2:IE-1,2:JE-1,2:KE-1)=gaz(2:IE-1,2:JE-1,2:KE-1)...
        .*(disp_z(2:IE-1,2:JE-1,2:KE-1)-iz(2:IE-1,2:JE-1,2:KE-1));
    iz(2:IE-1,2:JE-1,2:KE-1)=iz(2:IE-1,2:JE-1,2:KE-1)...
        +gbz(2:IE-1,2:JE-1,2:KE-1).*ez(2:IE-1,2:JE-1,2:KE-1);
    
        %计算hx
    curl_e(1:ia,1:ny-1,1:nz-1)=(ey(1:ia,1:ny-1,2:nz)...
        -ey(1:ia,1:ny-1,1:nz-1)-ra_y*(ez(1:ia,2:ny,1:nz-1)...
        -ez(1:ia,1:ny-1,1:nz-1)));
    ihxl(1:ia,1:ny-1,1:nz-1)=ihxl(1:ia,1:ny-1,1:nz-1)...
        +curl_e(1:ia,1:ny-1,1:nz-1);
    hx(1:ia,1:ny-1,1:nz-1)=fj3_3w(1:ia,1:ny-1,1:nz-1)...
        .*fk3_3w(1:ia,1:ny-1,1:nz-1).*hx(1:ia,1:ny-1,1:nz-1)...
        +fj2_3w(1:ia,1:ny-1,1:nz-1).*fk2_3w(1:ia,1:ny-1,1:nz-1)...
        *0.5.*(curl_e(1:ia,1:ny-1,1:nz-1)+fi1_3w(1:ia,1:ny-1,1:nz-1)...
        .*ihxl(1:ia,1:ny-1,1:nz-1));

    curl_e(ia+1:ib+1,1:ny-1,1:nz-1)=(ey(ia+1:ib+1,1:ny-1,1:nz-1)...
        -ey(ia+1:ib+1,1:ny-1,1:nz-1)-ra_y*(ez(ia+1:ib+1,2:ny,1:nz-1)...
        -ez(ia+1:ib+1,1:ny-1,1:nz-1)));
    hx(ia+1:ib+1,1:ny-1,1:nz-1)=fj3_3w(ia+1:ib+1,1:ny-1,1:nz-1)...
        .*fk3_3w(ia+1:ib+1,1:ny-1,1:nz-1).*hx(ia+1:ib+1,1:ny-1,1:nz-1)...
        +fj2_3w(ia+1:ib+1,1:ny-1,1:nz-1)...
        .*fk2_3w(ia+1:ib+1,1:ny-1,1:nz-1)...
        *0.5.*curl_e(ia+1:ib+1,1:ny-1,1:nz-1);

    curl_e(ib+2:nx,1:ny-1,1:nz-1)=(ey(ib+2:nx,1:ny-1,1:nz-1)...
        -ey(ib+2:nx,1:ny-1,1:nz-1)...
        -ra_y*(ez(ib+2:nx,2:ny,1:nz-1)-ez(ib+2:nx,1:ny-1,1:nz-1)));
    ihxh(1:ia,1:ny-1,1:nz-1)=ihxh(1:ia,1:ny-1,1:nz-1)...
        +curl_e(ib+2:nx,1:ny-1,1:nz-1);
    hx(ib+2:nx,1:ny-1,1:nz-1)=fj3_3w(ib+2:nx,1:ny-1,1:nz-1)...
        .*fk3_3w(ib+2:nx,1:ny-1,1:nz-1).*hx(ib+2:nx,1:ny-1,1:nz-1)...
        +fj2_3w(ib+2:nx,1:ny-1,1:nz-1).*fk2_3w(ib+2:nx,1:ny-1,1:nz-1)...
        *0.5.*(curl_e(ib+2:nx,1:ny-1,1:nz-1)...
        +fi1_3w(ib+2:nx,1:ny-1,1:nz-1).*ihxh(1:ia,1:ny-1,1:nz-1));

    %计算hy
    curl_e(1:nx-1,1:ja,1:nz-1)=(-ex(1:nx-1,1:ja,2:nz)...
        +ex(1:nx-1,1:ja,1:nz-1)+ra_x*(ez(2:nx,1:ja,1:nz-1)...
        -ez(1:nx-1,1:ja,1:nz-1)));
    ihyl(1:nx-1,1:ja,1:nz-1)=ihyl(1:nx-1,1:ja,1:nz-1)...
        +curl_e(1:nx-1,1:ja,1:nz-1);
    hy(1:nx-1,1:ja,1:nz-1)=fi3_3w(1:nx-1,1:ja,1:nz-1)...
        .*fk3_3w(1:nx-1,1:ja,1:nz-1).*hy(1:nx-1,1:ja,1:nz-1)...
        +fi2_3w(1:nx-1,1:ja,1:nz-1).*fk2_3w(1:nx-1,1:ja,1:nz-1)...
        *0.5.*(curl_e(1:nx-1,1:ja,1:nz-1)+fj1_3w(1:nx-1,1:ja,1:nz-1)...
        .*ihyl(1:nx-1,1:ja,1:nz-1));

    curl_e(1:nx-1,ja+1:jb+1,1:nz-1)=(-ex(1:nx-1,ja+1:jb+1,2:nz)...
        +ex(1:nx-1,ja+1:jb+1,1:nz-1)+ra_x*(ez(2:nx,ja+1:jb+1,1:nz-1)...
        -ez(1:nx-1,ja+1:jb+1,1:nz-1)));
    hy(1:nx-1,ja+1:jb+1,1:nz-1)=fi3_3w(1:nx-1,ja+1:jb+1,1:nz-1)...
        .*fk3_3w(1:nx-1,ja+1:jb+1,1:nz-1).*hy(1:nx-1,ja+1:jb+1,1:nz-1)...
        +fi2_3w(1:nx-1,ja+1:jb+1,1:nz-1)...
        .*fk2_3w(1:nx-1,ja+1:jb+1,1:nz-1)...
        *0.5.*curl_e(1:nx-1,ja+1:jb+1,1:nz-1);

    curl_e(1:nx-1,jb+2:ny,1:nz-1)=(-ex(1:nx-1,jb+2:ny,2:nz)...
        +ex(1:nx-1,jb+2:ny,1:nz-1)...
        +ra_x*(ez(2:nx,jb+2:ny,1:nz-1)-ez(1:nx-1,jb+2:ny,1:nz-1)));
    ihyh(1:nx-1,1:ja,1:nz-1)=ihyh(1:nx-1,1:ja,1:nz-1)...
        +curl_e(1:nx-1,jb+2:ny,1:nz-1);
    hy(1:nx-1,jb+2:ny,1:nz-1)=fi3_3w(1:nx-1,jb+2:ny,1:nz-1)...
        .*fk3_3w(1:nx-1,jb+2:ny,1:nz-1).*hy(1:nx-1,jb+2:ny,1:nz-1)...
        +fi2_3w(1:nx-1,jb+2:ny,1:nz-1).*fk2_3w(1:nx-1,jb+2:ny,1:nz-1)...
        *0.5.*(curl_e(1:nx-1,jb+2:ny,1:nz-1)...
        +fj1_3w(1:nx-1,jb+2:ny,1:nz-1).*ihyh(1:nx-1,1:ja,1:nz-1));

    %计算hz
    curl_e(1:nx-1,1:ny-1,1:ka)=(ra_y*(ex(1:nx-1,2:ny,1:ka)...
        -ex(1:nx-1,1:ny-1,1:ka))-ra_x*(ey(2:nx,1:ny-1,1:ka)...
        -ey(1:nx-1,1:ny-1,1:ka)));
    ihzl(1:nx-1,1:ny-1,1:ka)=ihzl(1:nx-1,1:ny-1,1:ka)...
        +curl_e(1:nx-1,1:ny-1,1:ka);
    hz(1:nx-1,1:ny-1,1:ka)=fi3_3w(1:nx-1,1:ny-1,1:ka)...
        .*fj3_3w(1:nx-1,1:ny-1,1:ka).*hz(1:nx-1,1:ny-1,1:ka)...
        +fi2_3w(1:nx-1,1:ny-1,1:ka).*fj2_3w(1:nx-1,1:ny-1,1:ka)...
        *0.5.*(curl_e(1:nx-1,1:ny-1,1:ka)+fk1_3w(1:nx-1,1:ny-1,1:ka)...
        .*ihzl(1:nx-1,1:ny-1,1:ka));

    curl_e(1:nx-1,1:ny-1,ka+1:kb+1)=(ra_y*(ex(1:nx-1,2:ny,ka+1:kb+1)...
        -ex(1:nx-1,1:ny-1,ka+1:kb+1))-ra_x*(ey(2:nx,1:ny-1,ka+1:kb+1)...
        -ey(1:nx-1,1:ny-1,ka+1:kb+1)));
    hz(1:nx-1,1:ny-1,ka+1:kb+1)=fi3_3w(1:nx-1,1:ny-1,ka+1:kb+1)...
        .*fj3_3w(1:nx-1,1:ny-1,ka+1:kb+1).*hz(1:nx-1,1:ny-1,ka+1:kb+1)...
        +fi2_3w(1:nx-1,1:ny-1,ka+1:kb+1)...
        .*fj2_3w(1:nx-1,1:ny-1,ka+1:kb+1)...
        *0.5.*curl_e(1:nx-1,1:ny-1,ka+1:kb+1);

    curl_e(1:nx-1,1:ny-1,kb+2:nz)=(ra_y*(ex(1:nx-1,2:ny,kb+2:nz)...
        -ex(1:nx-1,1:ny-1,kb+2:nz))...
        -ra_x*(ey(2:nx,1:ny-1,kb+2:nz)-ey(1:nx-1,1:ny-1,kb+2:nz)));
    ihzh(1:nx-1,1:ny-1,1:ka)=ihzh(1:nx-1,1:ny-1,1:ka)...
        +curl_e(1:nx-1,1:ny-1,kb+2:nz);
    hz(1:nx-1,1:ny-1,kb+2:nz)=fi3_3w(1:nx-1,1:ny-1,kb+2:nz)...
        .*fj3_3w(1:nx-1,1:ny-1,kb+2:nz).*hz(1:nx-1,1:ny-1,kb+2:nz)...
        +fi2_3w(1:nx-1,1:ny-1,kb+2:nz).*fj2_3w(1:nx-1,1:ny-1,kb+2:nz)...
        *0.5.*(curl_e(1:nx-1,1:ny-1,kb+2:nz)...
        +fk1_3w(1:nx-1,1:ny-1,kb+2:nz).*ihzh(1:nx-1,1:ny-1,1:ka));
    
    %画图
    if n==50
        for i=1:IE
            for j=1:JE
                ezkout(i,j)=ez(i,j,kc-5);
            end
        end
        
        [i,j]=meshgrid(1:1:IE,1:1:KE);
        subplot(2,2,1);
        mesh(i,j,(ezkout))
        surf(i,j,(ezkout))
        axis([1,IE,1,JE,-0.02,0.03]);
        title('T=50');
        subplot(2,2,2);
        contour(ezkout);
    end
    
     if n==80
        for i=1:IE
            for j=1:JE
                ezkout(i,j)=ez(i,j,kc-5);
            end
        end
        
        [i,j]=meshgrid(1:1:IE,1:1:KE);
        subplot(2,2,3);
        mesh(i,j,(ezkout))
        surf(i,j,(ezkout))
        axis([1,IE,1,JE,-0.02,0.03]);
        title('T=80');
        subplot(2,2,4);
        contour(ezkout);
     end
end

可以得到50和80个时间步下的偶极子天线辐射图:

Matlab仿真偶极子天线激励_第1张图片

 

你可能感兴趣的:(Matlab)