ok here i will provide the code in 2D then plz do the modiofication and convert it in to 3D..
% display sampled electric fields on a plane
for ind=1:number_of_sampled_transient_E_planes
figure(sampled_transient_E_planes(ind).figure);
Es = zeros(nxp1, nyp1);
component = sampled_transient_E_planes(ind).component;
switch (component)
case 'x'
Es(2:nx,: ) = 0.5 * (Ex(1:nx-1,: ) + Ex(2:nx,: ));
case 'y'
Es
,2:ny) = 0.5 * (Ey
,1:ny-1) + Ey
,2:ny));
case 'z'
Es = Ez;
case 'm'
Exs(2:nx,: ) = 0.5 * (Ex(1:nx-1,: ) + Ex(2:nx,: ));
Eys
,2:ny) = 0.5 * (Ey
,1:ny-1) + Ey
,2:ny));
Ezs = Ez;
Es = sqrt(Exs.^2 + Eys.^2 + Ezs.^2);
end
imagesc(xcoor,ycoor,Es.');
axis equal; axis xy; colorbar;
title(['Electric field <' component '>[' num2str(ind) ']']);
drawnow;
end
% capture sampled time harmonic electric fields on a plane
for ind=1:number_of_sampled_frequency_E_planes
w = 2 * pi * sampled_frequency_E_planes(ind).frequency;
Es = zeros(nxp1, nyp1);
component = sampled_frequency_E_planes(ind).component;
switch (component)
case 'x'
Es(2:nx,: ) = 0.5 * (Ex(1:nx-1,: ) + Ex(2:nx,: ));
case 'y'
Es( :,2:ny) = 0.5 * (Ey( :,1:ny-1) + Ey( :,2:ny));
case 'z'
Es = Ez;
case 'm'
Exs(2:nx,: ) = 0.5 * (Ex(1:nx-1,: ) + Ex(2:nx,: ));
Eys( :,2:ny) = 0.5 * (Ey ( :,1:ny-1) + Ey( :,2:ny));
Ezs = Ez;
Es = sqrt(Exs.^2 + Eys.^2 + Ezs.^2);
end
sampled_frequency_E_planes(ind).sampled_field = ...
sampled_frequency_E_planes(ind).sampled_field ...
+ dt * Es * exp(-j*w*dt*time_step);
end
plz tell me the correction to covert it into 3D electric field distribution..............