How can I plot the functions in my code according to theta?

Here is my code.
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.;
eps1=epsr1*eps0;
eps2=epsr2*eps0;
mu1=mur1*mu0;
mu2=mur2*mu0;
freq=299.7925*10^6;
omeg=2*pi*freq;
k=omeg*sqrt(eps1*mu1);
lambda=2*pi/k;
phi=45;
R=1.1;
for n=1:N_cut
bes_kur1(n)=sqrt(pi.*k.*R./2).*besselj(n+0.5,k.*R);
han_kur1(n)=sqrt(pi.*k.*R./2).*besselh(n+0.5,2,k.*R);
bes_kur_der1(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_der1(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);
han_kur_dd(n)=sqrt(pi.*k.*R./2).*besselh(n+2.5,2,k.*R)-sqrt(pi./(2.*k.*R)).*(2.*n+3).*besselh(n+1.5,2,k.*R)+sqrt(pi./(2.*(k.*R).^3)).*...
n.*(n+1).*besselh(n+0.5,2,k.*R);
a(n)=(1i.^(-n)).*(2.*n+1)./(n.*(n+1));
b(n)=(-a(n)).*bes_kur_der1(n)./han_kur_der1(n);
c(n)=(-a(n)).*bes_kur1(n)./han_kur1(n);
L1=legendre(n,cosd(theta));
L11=legendre(n-1,cosd(theta));
L2(n)=L1(2);
if n==1
L3(n)=0.;
else
L3(n)=L11(2);
end
L2_der(n)=(-(n+1).*L3(n)+n.*cosd(theta)).*L2(n)/sind(theta);
E_r=((-1i.*cosd(phi).*b(n).*L3(n).*(han_kur_dd(n)+han_kur1(n))));
E_theta=(cosd(phi)./(k.*R)).*((1i)*b(n)*han_kur_der1(n).*sin(theta).*L2_der(n)-c(n).*han_kur1(n)*(L3(n)./sin(theta)));
E_phi=(sin(phi))./(k.*R).*(((1i).*b(n).*han_kur_der1(n).*(L3(n)./(sin(theta))))-(c(n).*han_kur1(n).*sin(theta)).*L2_der(n));
end
F_Er=sum(E_r);
F_Etheta=sum(E_theta);
F_Ephi=sum(E_phi);
figure
plot(theta,abs(F_Er)),grid on
hold
figure
plot(theta,abs(F_Etheta)),grid on
hold
figure
plot(theta,abs(F_Ephi)),grid on
hold

3 Comments

You have not defined any theta. Are you hoping to represent it abstractly, to create the other variables as a function of a symbolic theta ?
yes exactly I want that , F_Er,F_Etheta , F_Ephi has to be function of theta.
Hmmm, okay, but are you going to be doing anything with the formulas afterwards that you need them to be in function form? Or do you just need to be able to plot, in which case you could possibly proceed with numeric theta?

Sign in to comment.

 Accepted Answer

At the beginning of the code, put in
syms theta
then before you go to plot, you need to choose specific theta to plot for, such as by
Thetas = linspace(0, 2*pi, 100);
val_F_Er = double( subs(F_er, theta, Thetas) );
val_F_Etheta = double( subs(F_Etheta, theta, Thetas) );
val_F_Ephi = double( subs(F_Ephi, theta, Thetas) );
figure
plot(Thetas, abs(val_F_Er));
figure
plot(Thetas, abs(val_F_Etheta));
figure
plot(Thetas, abs(val_F_Ephi));

8 Comments

now I got this error.? Error using ==> cosd at 16 Argument should be real. at L1=legendre(n,cosd(theta)); part.
No I dont need them for function form , I just want to plot functions according to thetas.And theta axis must be degree by the way.Thanks for help , I really appreciate
You will need to use cos(theta*pi/180) instead of cosd() if you are going to use syms. Similarly sin(theta*pi/180) instead of sind(). Then
Thetas = linspace(0, 359, 100); %or however many divisions you want
still have a problem with legendre polynomials.
Error in ==> conducting_sphere at 44 L1=legendre(n,cos(theta*pi/180));
??? Error using ==> legendre at 107 X must be real and in the range (-1,1).
Ummm. That starts to get messy. There is a symbolic legendre function http://www.mathworks.com/help/symbolic/mupad_ref/orthpoly-legendre.html but it creates DOM_POLY.
But is it correct that you only want the Order 1 legendre polynomial? As I see you are indexing the return array at (2) (corresponding to order 1). If so then it might be more practical to compute that one order directly.
yes here are my functions.
I need them and their derivatives as 1 order.And also my polynomials are associated legendre functions.
Could you post a higher resolution image of the functions?

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!