Error in solving differential of spherical Bessel function. How to solve it?

2 views (last 30 days)
fcntr (i.e. Frequency) is swept from 0.1 GHz to 12.5 GHz ...
Code:
k0a=((2*pi*fcntr)/(3e08));
k1a=((epi1/epi0)^(1/2))*(2*pi*fcntr/c0);
lambda0=c0/fcntr;
omega=2*pi*fcntr;
freq(cntr)=fcntr;
fnh=@(r1)(diff(sqrt(pi/(2*k1a*r1))*besselh(v+0.5,2,k1a*r1),r1));
Han=fnh(r);
Getting Error:
"Error using diff
Difference order N must be a positive integer scalar.
Error in @(r1)(diff(sqrt(pi/(2*k1a*r1))*besselh(v+0.5,2,k1a*r1),r1))
Error in SpericalBessel_cone (line 35)
Han=fnh(r);"
Kindly help to solve it.

Accepted Answer

Alan Stevens
Alan Stevens on 18 Sep 2020
Assuming fcntr is a vector of values then you need
lambda0=c0 ./ fcntr;
and
fnh=@(r1)(diff(sqrt(pi ./ (2*k1a*r1)) .* besselh(v+0.5,2,k1a*r1),r1));
Note:
./ and .* not just / and *

More Answers (1)

Walter Roberson
Walter Roberson on 18 Sep 2020
diff() has two major uses that are very different.
When the first parameter to diff() is numeric then the operation is finite differences, x(2:end)-x(1:end-1). There is an optional second parameter which is the number of times to repeat that operation. That optional parameter must be a positive integer since it is the number repetitions.
You are passing the variable of integration as the second parameter to diff, but the variable of integration will assume continuous values that are not typically integers.
The other major diff() is used only when the first parameter is symbolic expression or symbolic function. This is the calculus derivative operation. The optional second parameter would tend to be the symbolic variable to take the derivative with respect to, but it could instead be the number of times to take the derivative with respect to the default variable.
You are passing in a variable as the second parameter, but it is a numeric variable rather than a symbolic variable, so even if the first parameter were symbolic the numeric variable would not be correct for the number of times to take the derivative.
When I look at what you have written it looks to me as if you should be using the symbolic toolbox and using int()

Community Treasure Hunt

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

Start Hunting!