From: Nathan Zhang on
Thank you for your constant replies so much.

I changed my mind.

I used a large interval (such as n=-1000:.1:1000) to instead, tried my best to approach the infinity. And then used sum() function to find the sum of those results.

However, here is another problem.
After I got the sum, there is also a variable. And I need to plot the function with it. The following is the code:

a=0.01;
E0=8.85e-12;U0=pi*4e-7;c=3e8;
z=a*2*pi*c*sqrt(E0*U0); %To be used in besselh()
n=-10:.1:10;syms phi; %Define the interval
f=j.^(-n).*exp(j.*n.*phi)./(besselh(n,2,z)); %The function I tried to find a sum
SUM=sum(f) %Find the sum
phi=0:2*pi/200:2*pi; %Define the variable
J=1/(a*c*U0*pi^2)*SUM; %The final function
plot(phi,J)


But I got an error
Conversion to double from sym is not possible.


I know this may stem from "syms phi", or can't plug the variable "phi" into the SUM, but I don't know how to fix it. Can you help me firgure out how to plot the equation or is my idea to find a sum correct ??

Thank you so much.
From: Steven Lord on

"Nathan Zhang" <hj_zhangs(a)tom.com> wrote in message
news:hqjhlj$an4$1(a)fred.mathworks.com...
> Thank you for your constant replies so much.
>
> I changed my mind.
> I used a large interval (such as n=-1000:.1:1000) to instead, tried my
> best to approach the infinity. And then used sum() function to find the
> sum of those results.
>
> However, here is another problem.
> After I got the sum, there is also a variable. And I need to plot the
> function with it. The following is the code:
>
> a=0.01;
> E0=8.85e-12;U0=pi*4e-7;c=3e8;
> z=a*2*pi*c*sqrt(E0*U0); %To be used in besselh()
> n=-10:.1:10;syms phi; %Define the interval
> f=j.^(-n).*exp(j.*n.*phi)./(besselh(n,2,z)); %The function I tried
> to find a sum
> SUM=sum(f) %Find the sum
> phi=0:2*pi/200:2*pi; %Define the variable
> J=1/(a*c*U0*pi^2)*SUM; %The final function
> plot(phi,J)
>
>
> But I got an error
> Conversion to double from sym is not possible.

This error arises when you try to PLOT your results. J is a sym object and
PLOT expects its inputs to be numeric. Use SUBS to substitute values into J
for the symbolic variable phi and PLOT phi versus the numeric result of that
substitution. You may want to create two plots, actually; one versus the
real part of the substituted result and one versus the imaginary part.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Walter Roberson on
Nathan Zhang wrote:

> phi=0:2*pi/200:2*pi; %Define the variable
> J=1/(a*c*U0*pi^2)*SUM; %The final function
> plot(phi,J)

> But I got an error
> Conversion to double from sym is not possible.

JN = subs(J);
plot(phi, J);
From: Walter Roberson on
Nathan Zhang wrote:

> Even the value of "nu" is from 0 to +infinity as integer, how to find
> the sum??

You cannot. The besselh documentation indicates that besselh is not
defined when nu is an integer. If you examine the definition of besselh,
you will see there is a sin(nu*Pi) in the denominator, and that is
going to be 0 for every integer nu .

> Since I can't use a symbolic letter "n" to set it into "nu" in
> the function besselh(), I still have no idea to solve the problem.

Don't worry about that part, it isn't an issue. You would just put n in
the position that nu is expected. Your bigger problem is that the
function is not defined at any integer. When you were attempting to sum
from -infinity to +infinity then you had the wiggle room of saying "Ah,
but -infinity is not necessarily an integer, so I might not be summing
over the integers!", but when you start the summation from 0 then
because the symbolic summation operator is defined to increment the
dummy variable by exactly one (1) each time, you are locking yourself in
to integers. That's why I mentioned in my comments that I had tried
summing n+1/10 -- the 1/10 transforming the integer n into something
that was non-integer. Using n+9/10 gave a fairly different numeric
answer, by the way.

You have the fundamental difficulty that what you are asking to do is
not well-defined; we should not be surprised that there is no
closed-form formula for a problem that is not well defined.

Maple is able to do numeric integration with its HankelH2 function.
Maple does not object to integers for nu, which is a matter that I will
ask the people who make Maple about.
From: Walter Roberson on
Nathan Zhang wrote:

> f=j.^(-n).*exp(j.*n.*phi)./(besselh(n,2,z)); %The function I tried
> to find a sum
> SUM=sum(f) %Find the sum

It is frustrating to do a lot of work to try to find a good symbolic
formula for something, only to find that the user _really_ wanted quite
a different formula.

sum(g(n)/h(n),n=-infinity..infinity) is NOT the same as
sum(g(n),n=-infinity..infinity) / sum(h(n),n=-infinity..infinity)

The interaction between the n of the exp(j*n*phi) and the n of
besselh(n,2,z) _matters_ .


My symbolic package is telling me that
simplify(convert(Sum(f,n=-10..10),Int)) is 0, but with numeric
substitution, I think it is mistaken. It is difficult to say: with the
definition of besselh(n,2,z) as given by Matlab, which would be
HankelH2(n,z) in my symbolic package, if I do any kind of symbolic
transformation in an attempt to find a closed form for the summation,
the package quickly complains about division by 0 -- which is an issue I
was pointing out to you before, that nu is documented as being
non-integral .

I am trying to follow up with Mathworks as to why they document nu as
non-integral and yet do not error out (and produce a seemingly
meaningful answer) when nu is integral. And I will follow up and see if
I can trace down why my symbolic package thinks it is okay to simply the
integral directly (an issue that I also ran into for someone else last
night.)