Why the function I wrote doesnt plot ?
1 view (last 30 days)
Show older comments
I wrote a function that calculates E(theta) for PEC sphere about electromagnetic plane wave scattering but it does not plot.Where is my fault ?thanks for your help.
format long
tic
N_cut=20;
eps0=(10^-9)/(36*pi);
mu0=4*pi*10^-7;
epsr1=1.;
epsr2=2.;
mur1=1.;
mur2=1.;
R=linspace(0,2,N_cut);
global phid;
global thetad;
eps1=epsr1*eps0;
eps2=epsr2*eps0;
mu1=mur1*mu0;
mu2=mur2*mu0;
freq=6*10^8;
omeg=2*pi*freq;
k=omeg*sqrt(eps1*mu1);
lambda=2*pi/k;
for phid=1:360
for thetad=1:180
phi(phid)=phid*180/pi;
theta(thetad)=thetad*180/pi;
end
end
for thetad=1:180
for n=1:N_cut
bes_kur(n,:)=sqrt(pi.*k.*R./2).*besselj(n+0.5,k.*R);
han_kur(n,:)=sqrt(pi.*k.*R./2).*besselh(n+0.5,2,k.*R);
bes_kur_der(n,:)=-n.*sqrt(pi.*k./(2.*R)).*besselj(n+0.5,k.*R)+k.*sqrt(pi.*k.*R./2).*besselj(n-0.5,k.*R);
han_kur_der(n,:)=-n.*sqrt(pi.*k./(2.*R)).*besselh(n+0.5,2,k.*R)+k.*sqrt(pi.*k.*R/2).*besselh(n-0.5,2,k.*R);
a(n,:)=(1i.^n).*(2.*n+1);
b(n,:)=-((1i.^n).*(2.*n+1).*bes_kur_der(n))./han_kur_der(n);
c(n,:)=-((1i.^n).*(2.*n+1).*bes_kur(n))./han_kur(n);
L1=legendre(n,cos(theta(thetad)));
L11=legendre(n-1,cos(theta(thetad)));
L2(n,thetad)=L1(2,:);
if n==1
L3(n,thetad)=0.;
else
L3(n,thetad)=L11(2,:);
end
L2_der(n,thetad)=(-(n+1).*L3(n,thetad)+n.*cos(theta(thetad)).*L2(n,thetad))/sin(theta(thetad));
E_theta=(1i^n).*((b(n).*sin(theta(thetad))).*L2_der(n,thetad)).*(c(n).*L3(n,thetad)./sin(theta(thetad)));
end
end
F_Etheta=sum(E_theta,2);
figure
plot(R,abs(F_Etheta))
hold
0 Comments
Answers (2)
Walter Roberson
on 6 Apr 2013
You are overwriting all of E_theta every time through the loops, so at the end it is a scalar.
4 Comments
Youssef Khmou
on 7 Apr 2013
hi, The function does not plot because the data contains NaN values in both Real and Imaginary parts , so try to change the code, the NaN values occurs in the loop, also the arguments for SIN /COS should be in Radian not Degree or use 'sind' and 'cosd' instead , i tried to change the code, try to verify the vectors 'a' 'b'and 'c' :
clear all,
format long
tic
N_cut=20;
eps0=(10^-9)/(36*pi);
mu0=4*pi*10^-7;
epsr1=1.;
epsr2=2.;
mur1=1.;
mur2=1.;
R=linspace(0,2,N_cut);
eps1=epsr1*eps0;
eps2=epsr2*eps0;
mu1=mur1*mu0;
mu2=mur2*mu0;
freq=6*10^8;
omeg=2*pi*freq;
k=omeg*sqrt(eps1*mu1);
lambda=2*pi/k;
thetad=1:0.5:180;
for t=1:length(thetad)
for n=1:N_cut
% THE PROBLEM IS IN THIS LOOP BES,BES',HAN, and HAN' contain
% NaN so you cant visualize the Result
% Temporal solution : Replace NaN with ZERO.
A=sqrt(pi.*k.*R./2).*besselh(n+0.5,2,k.*R);
A(isnan(A))=0;
bes_kur(n,:)=A;
B=sqrt(pi.*k.*R./2).*besselh(n+0.5,2,k.*R);
B(isnan(B))=0;
han_kur(n,:)=B;
C=-n.*sqrt(pi.*k./(2.*R)).*besselj(n+0.5,k.*R)+k.*sqrt(pi.*k.*R./2).*besselj(n-0.5,k.*R);
C(isnan(C))=0;
bes_kur_der(n,:)=C;
D=-n.*sqrt(pi.*k./(2.*R)).*besselh(n+0.5,2,k.*R)+k.*sqrt(pi.*k.*R/2).*besselh(n-0.5,2,k.*R);
D(isnan(D))=0;
han_kur_der(n,:)=D;
a(n)=(1i.^n).*(2.*n+1);
b(n)=(-((1i.^n).*(2.*n+1).*bes_kur_der(n)))./han_kur_der(n);
c(n)=-((1i.^n).*(2.*n+1).*bes_kur(n))./han_kur(n);
L1=legendre(n,cos(thetad(t)*pi/180));
L11=legendre(n-1,cos(thetad(t)*pi/180));
L2(n,t)=L1(2,:);
if n==1
L3(n,t)=0.;
else
L3(n,t)=L11(2,:);
end
L2_der(n,t)=(-(n+1).*L3(n,t)+n.*cos(thetad(t)*pi/180).*L2(n,t))/sin(thetad(t)*pi/180);
E_theta(n)=(1i^n).*((b(n).*sin(thetad(t)*pi/180)).*L2_der(n,t)).*(c(n).*L3(n,t)./sin(thetad(t)*pi/180));
end
end
%F_Etheta=sum(E_theta,2);
figure
plot(R,abs(E_theta))
3 Comments
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!