2
$\begingroup$

I am trying to animate the general solution to a particle in a box (Schrodinger eqn), but anytime I change B to something greater than 0, it gives me the limit of summation error message. I apologize if my mistake is a trivial one, but I couldn't find any answers online. Here is my code:

ClearAll
Clear[m, l, h, x, t, z, k, n, B]
\[Psi][x_, t_] := 
  Sum[B*Sin[(n*\[Pi]*x)/l]*Exp[(-I*t*\[Pi]*n^2)/(2*l^4)], {n, 0, k}];
Manipulate[
 ComplexPlot3D[\[Psi][x, t], {z, -10 - 10 I, 10 + 10 I}], {k, 0, 
  10}, {t, 0, 10}, {B, 0, 10}, {l, 0, 10}]

Additionally, I have found that mathematica refuses to evaluate simple expressions that I know it knows how to evaluate, though many of those instances were due to ClearAll not actually clearing all variables (which is annoying, but whatever); however, I think this may be an instance of this, as I have also found that if I define a variable, I cannot use it in an expression and expect mathematica to completely solve it as it will just spit back the expression with the value of the variable substituted in, instead of the final evaluated expression. For example, if I define k=npi/l, then if I were to do Integrate[kx], it would return Integrate[(npi/l)*x] (obviously not with this syntax though, I lost the code that this happened to me with, but hopefully this got the point across). I suspect this kept happening to me because I did not use :=, which I have now started using and although it has not happened to me again since, I thought it pertinent to this conversation as I believe mathematica is just not assigning k the value that I set using the Manipulate UI, thus it tries to evaluate the series from 0 to k instead of 0 to k=number. Perhaps I'm not correct in thinking that though lol. Anyways, the first issue still persists and I don't know why. Any help would be greatly appreciated.

New contributor
Jibran Syed is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
2
  • $\begingroup$ B*Sin[(n*\[Pi]*x)/l]*Exp[(-I*t*\[Pi]*n^2)/(2*l^4)] does not contain a k term for the summation. $\endgroup$ Aug 6 at 11:07
  • $\begingroup$ Does anyone know if we have a canonical Q&A for this sort of problem with scoping in Manipulate? (Of course, with most Manipulate problems, there are a couple of other issues that confuse & conflate the problem with others and make an "exact duplicate" difficult to find.) $\endgroup$
    – Michael E2
    Aug 6 at 14:30

1 Answer 1

5
$\begingroup$

You have few errors

Try the following. Changed your l to d as l is horrible letter for a variable as it looks like 1.

Always pass arguments you want to use in a function via arguments. Do not keep things global. This is true in any language. Also add Tracking to Manipulate.

You might want to fix the vertical range to some value to better see the effect of moving the slider, as it changes over such a very large values. Now the range is Automatic or change the values where each slider can move over. This depends on the Physics itself and what values you want to change.

Mathematica graphics

code

ClearAll
Clear[m, d, h, x, t, z, k, n, B]

ψ[x_, t_, k_, B_, d_] := 
  Sum[B*Sin[(n*π*x)/d]*Exp[(-I*t*π*n^2)/(2*d^4)], {n, 0, k}];
Manipulate[
 ComplexPlot3D[ψ[z, t, k, B, d], {z, -10 - 10 I, 10 + 10 I}],
 {{k, 1, "k"}, 1, 10, 1, Appearance -> "Labeled"},
 {{t, 1, "t"}, 1, 10, 1, Appearance -> "Labeled"},
 {{B, 1, "B"}, 1, 10, 1, Appearance -> "Labeled"},
 {{d, 1, "d"}, 1, 10, 1, Appearance -> "Labeled"},
 TrackedSymbols :> {k, t, B, d}]
$\endgroup$

Your Answer

Jibran Syed is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.