How to use spherical Hankel fumction to obtain sphere scatter

6 views (last 30 days)
c=3e8;
f=6e9;
n=10;
i=1:n;
Wl=c/f;
k=(2*pi)/Wl;
radius=1e-2:1e-4:6e-2;
r=length(radius);
kr=k*radius;
X=radius/Wl;
Ae=zeros(1,r);
syms nu x
J=sqrt(pi/(2*x)).*besselj(nu+0.5,x);
Y=sqrt(pi./(2*x)).*bessely(nu+0.5,x);
H=J-1j*Y;
dH=diff(H);
ht=H.*dH;
nu=i;x=kr;
B=eval(ht);
Error using besselj
NU and Z must be the same size or one must be a scalar.

Error in sym/eval (line 13)
s = evalin('caller',vectorize(char(x)));
A(i,:)=(abs(((-1^i)*(2*i+1))./(B)).^2)./(4*pi);
Ae(1,:)=A(i,:)+Ae(1,:);
figure(1);
plot(X,Ae);
we want to use this formula to evaluate the echo area of a conducting sphere of radius a,the upper code is my try,but it didnt work. Please someone tell me what's wrong with my code,thank you.

Answers (1)

Aakash
Aakash on 26 Jun 2023
The error in your code arises from the fact that the variable nu is a symbolic variable defined using syms, while x is a numeric array (kr). The besselj function requires both inputs to have the same size or one to be a scalar.
To fix this, you can use a for loop to evaluate the expression for each value of i and radius like this:
c = 3e8;
f = 6e9;
n = 10;
i = 1:n;
Wl = c / f;
k = (2 * pi) / Wl;
radius = 1e-2:1e-4:6e-2;
r = length(radius);
kr = k * radius;
X = radius / Wl;
Ae = zeros(1, r);
for i = 1:n
B = zeros(1, r);
for j = 1:r
x = kr(j);
H = besselj(i, x) - 1j * bessely(i, x);
dH = (1/2) * (besselj(i-1, x) - besselj(i+1, x) - 1j * (bessely(i-1, x) - bessely(i+1, x)));
ht = H * dH
B(j) = subs(ht, x, kr(j))
end
A = (abs(((-1)^i) * (2 * i + 1) ./ B).^2) / (4 * pi);
Ae = A + Ae;
end
figure(1);
plot(X, Ae);
  1 Comment
Dyuman Joshi
Dyuman Joshi on 26 Jun 2023
There's no point of using subs(), as there is no symbolic expression or function in the code.
Also, you can define H and dH as function handles, and calling them for each iteration and directly substituting input values.
Another good practice is to not use i and j as loop indices, especially when you will be using any or both of them as the imaginary constant.

Sign in to comment.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!