You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Mathematica绘制与附图风格相似的量子谐振子图像?

Plotting Quantum Harmonic Oscillator in Mathematica (Matching Reference Figure Style)

Hey there! Let's break down how to create quantum harmonic oscillator plots in Mathematica that align with your reference figure. I'll focus on the most common visualization style: overlaying probability densities for different energy levels with the classical potential well—adjustments can be made if your target plot has specific tweaks like 3D surfaces or custom coloring.

Step 1: Define Core Functions

First, we'll set up dimensionless versions of the quantum harmonic oscillator wavefunction, its probability density, and the classical potential. Using dimensionless variables keeps the math clean and matches standard textbook visuals:

(* Dimensionless wavefunction for quantum harmonic oscillator *)
ψ[n_, x_] := 1/Sqrt[2^n n! Sqrt[π]] Exp[-x^2/2] HermiteH[n, x]

(* Probability density |ψₙ(x)|² *)
probDensity[n_, x_] := Abs[ψ[n, x]]^2

(* Classical potential energy (dimensionless) *)
potential[x_] := x^2/2

(* Energy levels for each quantum state (Eₙ = n + 1/2, dimensionless) *)
energyLevel[n_] := n + 1/2

Step 2: Plot Probability Densities with Potential Well

The most common reference style shows each quantum state's probability density placed at its corresponding energy level, filled down to the level line, alongside the classical potential. Here's the code to generate that:

(* Choose which energy levels to plot (e.g., n=0 to 3) *)
levelsToPlot = Range[0, 3];

Plot[
 Evaluate[
  {
   potential[x],  (* Classical potential curve *)
   Sequence @@ Table[probDensity[n, x] + energyLevel[n], {n, levelsToPlot}],  (* Prob densities shifted to their energy levels *)
   Sequence @@ Table[energyLevel[n], {n, levelsToPlot}]  (* Horizontal lines for each energy level *)
  }
 ],
 x ∈ {-4, 4},  (* Adjust x-range to match your reference *)
 PlotLegends -> Join[
   {"Classical Potential V(x)"},
   Table["n=" <> ToString[n] <> " (|ψ|² + Eₙ)", {n, levelsToPlot}],
   Table["Eₙ = " <> ToString[energyLevel[n]], {n, levelsToPlot}]
 ],
 PlotStyle -> Join[
   {{Black, Thick}},  (* Bold black for potential *)
   Table[ColorData[97][n+1], {n, levelsToPlot}],  (* Distinct colors for each density curve *)
   Table[{Black, Dashed}, {n, levelsToPlot}]  (* Dashed lines for energy levels *)
 ],
 Filling -> Table[{n+1 -> {n + 1 + Length[levelsToPlot]}}, {n, levelsToPlot}],  (* Fill density curve down to its energy level *)
 FillingStyle -> Table[{Opacity[0.3], ColorData[97][n+1]}, {n, levelsToPlot}],  (* Semi-transparent fill *)
 AxesLabel -> {"x (Dimensionless)", "Energy / Probability Density"},
 PlotRange -> All,
 GridLines -> Automatic,
 BaseStyle -> {FontSize -> 12}
]

Step 3: Tweak to Match Your Exact Reference

If your reference has different styling, adjust these parameters:

  • Color Scheme: Replace ColorData[97] with other built-in palettes like ColorData["Pastel"] or specify exact colors (e.g., RGBColor[0.2, 0.6, 0.8]).
  • Filling: If your plot fills to the x-axis instead of energy levels, change Filling to Table[{n+1 -> Axis}, {n, levelsToPlot}].
  • x-Range: Modify x ∈ {-4, 4} to match the range in your reference (e.g., -5 to 5 for higher energy levels).
  • Line Thickness: Add Thick/Thin to the PlotStyle entries for density curves if needed.
  • 3D Plots: If your reference is a 3D surface (e.g., for a 2D harmonic oscillator), use Plot3D[probDensity[n, Sqrt[x^2 + y^2]], {x, -4, 4}, {y, -4, 4}, ...] instead.

内容的提问来源于stack exchange,提问作者Bikash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:02:02