How do I get rid of this "DOUBLE Cannot Convert to Double Array Error"?

6 views (last 30 days)
Hey! So, I don't really know too much about matlab but need to write a program to demonstrate the electric potential using a contour plot. Now, I've tried to input the code as best as possible but I'm getting this error:
Error using contour (line 55) DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use VPA.
Error in As1 (line 6) contour(x,y,v)
Can someone please help me and tell me how to write the code? The equation I'm trying to input is:
The code I've written is as follows:
a = 10;
b = 5;
[x,y] = meshgrid(0:0.5:10,0:0.5:5);
syms n x y
v = ((4*100)/pi)*symsum((1/n)*(sin(n.*pi*y/b))*(cosh(n.*pi*x/b)+sinh(n.*pi*x/b)).*((1-cosh(n*pi*a/b))/sinh(n*pi*a/b)), n , 1, Inf);
contour(x,y,v)
end
Also, some of you might have noticed that in my sum, I only want odd numbers. I have no idea how to do that so if someone could help me out with that as well, I've be very grateful.
Thanks!

Answers (1)

Walter Roberson
Walter Roberson on 18 Sep 2015
Your symsum involves x and y and n, and so would at best be reduced to being a formula in x and y. You then try to contour() the symbolic formula over the symbolic ranges x and y.
You need to pick a definite numeric range for x and y, create a meshgrid or ndgrid of those values, and substitute into the formula.
To make the adjustment for odd n, substitute n = 2*N+1, N over 0 to infinity.
My tests so far suggest that the sum is not convergent and that for any leading prefix of infinity, the plot oscillates infinitely over (x,y). Perhaps if the range were to be drastically restricted.
  9 Comments
Walter Roberson
Walter Roberson on 25 Sep 2015
I am almost certain this does not converge. If you try x=2 y=3 then look near at the individual contributions to the sums near k=10000 you can see that the contributions have a positive/negative cycle of length lcm(2,3) = 6, and that the values are getting larger every cycle, going way above 10^1000. Even in the k up to 20 or so you can see that the values get about 10^5 larger for each cycle of 6 elements.
Walter Roberson
Walter Roberson on 25 Sep 2015
The following discussion pertains to x = 2, y = 3:
I miscounted, the cycle is length 5. And yes, I can prove that it is divergent.
If you take the individual terms for k and convert the cosh to exp() format, you get
P(k) = (exp(2*(2*k-1)*Pi)-1) * exp((2/5)*(2*k-1)*Pi) * sin((3/5)*(2*k-1)*Pi) / ((exp(2*(2*k-1)*Pi)+1)*(2*k-1))
For larger k, the (exp(2*(2*k-1)*Pi)-1) on the numerator will be the same to working precision as the exp(2*(2*k-1)*Pi)+1) on the denominator. You can effectively drop those terms out, getting
P(k) = exp((2/5)*(2*k-1)*Pi) * sin((3/5)*(2*k-1)*Pi) / (2*k-1)
We are working with integer k, so we can ask the question of whether (3/5)*(2*k-1) can be an integer, as then you would have sin(integer*Pi) which would be 0. The answer is Yes, depending upon mod(k,5). If we write k = 5*L+M, M being 0, 1, 2, 3, or 4, for some positive integer L, then we can see in particular that for M=3, (3/5)*(2*(5*L+M)-1) will be an integer and therefore P(k) will be 0 with a period of 5, for the integers that end in 3 or 8 in decimal form.
Test then the other values of M and reduce the period in the sin() and you will find that two of the varieties involve sin(Pi/5) and two involve sin(2*Pi/5), with two each of them being positive or negative. These are effectively constant terms with period 5.
The denominator, (2*k-1), is a linear term. It is increasing with k, which might give a faint tinge of hope that the terms reduce in magnitude for increasing k. But the hope does not carry through.
We are left then with consideration of the term
exp((2/5)*(2*k-1)*Pi)
and that clearly grows exponentially large with increasing k. Exponential terms dominate over linear changes.
We therefore must conclude that although there are a mix of positive and negative terms, that once we have reached a k large enough for the numerator and denominator terms with the exp(something +/- 1) to numerically cancel out, then the following terms have magnitudes that are increasing exponentially for with period 5 (except that every 5th term is a 0.) This cannot converge. The infinite sum is undefined.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!