سؤال

Mathematica: Filling an infinitely deep potential well

Comment: The proper page for Mathematica questions is this one

I would like to visualize a potential well for a particle in a box in Mathematica similar to the second picture from Wikipedia here. I have defined my function piecewise

(*Length of the box*)
L     = 4; 

(*Infinitly deep potential well between 0 and L*)
V[x_] := Piecewise[{
            {\[Infinity], x <= 0},
            {0, 0 < x < L}, 
            {\[Infinity], L <= x}}]

and would like to obtain a plot function which gives a filled area where the potential goes to infinity.

Unfortunately my tries end up in shaded areas between the "zero region" of the potential, while I would like to have the shading in the infinity region.

Table[Plot[V[x], {x, -5, 10}, 
Filling -> f], {f, {Top, Bottom, Axis, 0.3}}]
هل كانت مفيدة؟

المحلول

The problem is that Infinity is too much for plot. So let's just give it some other big number. But to prevent it from rescaling the y axis we need to be specific with the upper plot range

Block[{\[Infinity] = 1*^1},
 Plot[V[x], {x, -5, 10},  Filling -> Bottom, 
  PlotRange -> {Automatic, 1}]
 ]

Alternatively you could plot V[x]/.\[Infinity]->1*^1 instead of Block but I like Block's way better

نصائح أخرى

Just give it values instead of infinity:

(*Length of the box*)L = 4;

(*Infinitly deep potential well between 0 and L*)

V[x_] := Piecewise[{{1, x <= 0}, {0, 0 < x < L}, {1, L <= x}}]
Plot[V[x], {x, -5, 10}, Filling -> Bottom]

plot

Another way using graphic primitives:

wellLeft = 0;
leftBorder = wellLeft - 1;
rightBorder = L + 1;
wellRight = L;
top = 5;
Graphics[{
  Hue[0.67, 0.6, 0.6],
  Opacity[0.2],
  Rectangle[{leftBorder, 0}, {wellLeft, top}],
  Rectangle[{wellRight, 0}, {rightBorder, top}]
  }, Axes -> True]

enter image description here

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top