Message Boards Message Boards

0
|
5682 Views
|
7 Replies
|
9 Total Likes
View groups...
Share
Share this post:

How do I make this summation numerical?

Posted 11 years ago
Hi,

I don't understand why I can't make the below numerical?
NSum[NSum[(2^(m + p)), {m, 1, 2}], {p, 1, 2}]

It gives:
Error - NSum::nsnum: Summand (or its derivative) 2^(m+p) is not numerical at point m = 1. >>
POSTED BY: Luke Foley
7 Replies
p is symbolic for the inner NSum
NSum[(2^(m + p)), {m, 1, 2}, {p, 1, 2}]
gives 36. without the error msg.
POSTED BY: Frank Kampas
Posted 11 years ago
That's great! Thanks!
Is there a way for this to work?    NSum[{m, p}, {m, 1, 3}, {p, 1, 2}]
POSTED BY: Luke Foley
NSum[#, {m, 1, 3}, {p, 1, 2}] & /@ {m, p}
{12., 9.}
POSTED BY: Frank Kampas
Posted 11 years ago
Thanks, I wouldn't have come up with that myself!
The reason is that I'm trying to get the following to plot:
n=2
a=10
R[m_, p_] := {m*a, p*a}
K[m_, p_] := {(2*Pi*m)/a, (2*Pi*p)/a}
A[x_, y_] := Sum[(-(-1)^(m*p + m + p) Exp[(-(K[m, p]*K[m, p])*a^2)/(8*Pi)])*(1 - Cos[K[m, p]*{x, y}]), {m, 1, 5}, {p, 1, 5}]
s[m_, p_] := -R[m, p] ((Sqrt[3]*a^2)/(4*Pi*R[m, p]*R[m, p]) + (0.068*a^4)/(R[m, p]*R[m, p]*R[m, p]*R[m, p]))
w[x_, y_] := A[x, y]/A[x/n, y/n] Product[(A[({x, y} - R[m, p] - s[m, p])/n]/A[({x, y} - R[m, p])/n]), {m, 1, 5}, {p, 1, 5}]
StreamPlot[w[x, y], {x, 1, 10}, {y, 1, 10}]
At the moment it gives a blank plot so I'm attempting to make it numerical in the hope that it may work. However I'm really struggling to get it to be numerical.
Any advice?
Thank you!
POSTED BY: Luke Foley
Posted 11 years ago
A powerful debugging trick I often use when some kind of plot doesn't display anything:
In your latest version of your code change
StreamPlot[w[x, y], {x, 1, 10}, {y, 1, 10}]
to
Table[w[x,y],{x,1,10},{y,1,10}]
and take a look at the result, you might need to then ask Mathematica to show you more and more output to see enough to be useful.

I see lots of
A[{someconstant,someotherconstant}]
in that and you have no definition for A that involves two items in a list, only an A that accepts two numeric arguments.

So I think the problem lies in several places where you give your A the result of vector operations.

If I make a guess that you might want this to be A[someconstant,someotherconstant] then I can try
A[Sequence@@(yourvectorexpression)]
where i have added an extra layer of () around your vector expression given to A, which should turn your vectors being given to A into a simple pair of arguments.

When I try Table on this I get a variety of warnings about 1/0 and indeterminant and complex infinities, but at least I no longer get unevaluated copies of A[...] and you might be able to tell whether the values in the resulting Table are sensible or not.

When I replace Table with StreamPlot it seems to take longer than I want to wait and this may indicate that I have misunderstood your code and even broken something.
Perhaps something in this will let you diagnose why you are not getting the plot you desire.

EDIT: Wait a minute, well actually perhaps more like ten minutes, and I actually get a StreamPlot from
StreamPlot[w[x,y],{x,1,3},{y,1,3}]
so with time you might also get a result, possibly even for 1 to 10 if you wait long enough
POSTED BY: Bill Simpson
Posted 11 years ago
Thanks! Seems I should have put:
A[{x_, y_}] :=
POSTED BY: Luke Foley
Posted 11 years ago
Using the Table trick after changing to A[{x_,y_}]:=..., it shows you have A[x,y] in some places and A[{x,y}] in other places.
What I should have done was sorted all this out and made all of them consistent.
Instead I cheated and just made two definitions for A,
A[{x_,y_}:=...
A[x_,y_]:=...
with identical right hand sides.
I also separated each of your statements with a semicolon, always a good idea and will keep you out of trouble in the future.
With those changes and after a depressingly long time your stream plot appears.
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract