I'm new to Mathematica and I'm trying to plot a Gaussian function (actually a sum of three Gaussian functions) using custom x-axis tick marks.
Here's what I have so far:
a0 = QuantityMagnitude[UnitConvert[Quantity[1, "BohrRadius"]]];
c1 = 0.154329;
c2 = 0.535328;
c3 = 0.444635;
a1 = 2.227660;
a2 = 0.405771;
a3 = 0.109818;
z1 = (2 * a1 / pi)^(3/4) Exp[-a1 * (x / a0)^2];
z2 = (2 * a2 / pi)^(3/4) Exp[-a2 * (x / a0)^2];
z3 = (2 * a3 / pi)^(3/4) Exp[-a3 * (x / a0)^2];
Plot[y = a0^(-3/2) * (c1 * z1 + c2 * z2 + c3 * z3),
PlotRange -> {{-15a0, 15a0}},
Ticks -> {Table[{k a0, Style[If[k > 1, Row[{k, Subscript[a, 0]}], Subscript[a, 0]],
Small]},
{k, -15, 15}], Automatic}]
I'm getting a really basic error (Plot::argr: Plot called with 1 argument; 2 arguments are expected.), but I'm not sure where I'm going wrong.
EDIT: Thanks to Alexei Boulbitch, here's my final code after edits.
a0 = QuantityMagnitude[UnitConvert[Quantity[1, "BohrRadius"]]];
Subscript[c, 1] = 0.154329;
Subscript[c, 2] = 0.535328;
Subscript[c, 3] = 0.444635;
a1 = 2.227660;
a2 = 0.405771;
a3 = 0.109818;
Subscript[\[Phi], 1] = (2*a1/Pi)^(3/4) Exp[-a1*(x/a0)^2];
Subscript[\[Phi], 2] = (2*a2/Pi)^(3/4) Exp[-a2*(x/a0)^2];
Subscript[\[Phi], 3] = (2*a3/Pi)^(3/4) Exp[-a3*(x/a0)^2];
Subscript[\[Psi], 1s] = a0^(-3/2)*(Subscript[c, 1] * Subscript[\[Phi], 1] +
Subscript[c, 2] * Subscript[\[Phi], 2] +
Subscript[c, 3] * Subscript[\[Phi], 3]);
Subscript[\[Psi], 1sActual] = a0^(-3/2) / Sqrt[Pi] * Exp[-x/a0];
str = ToString[Subscript["\[Psi]", "1s"], StandardForm];
Plot[{Subscript[\[Psi], 1s], Subscript[\[Psi], 1sActual]}, {x, 0, 7a0},
PlotLegends-> "Expressions",
Ticks -> {Table[{k a0, Style[If[k > -8, Row[{k, Subscript[a, 0]}],
Subscript[a, 0]],
Small]},
{k, 0, 7}], Automatic}]
Plot[{Subscript[\[Phi], 1], Subscript[\[Phi], 2], Subscript[\[Phi], 3],
(Subscript[c, 1] * Subscript[\[Phi], 1] + Subscript[c, 2] *
Subscript[\[Phi], 2] +
Subscript[c, 3] * Subscript[\[Phi], 3])}, {x, -7a0, 7a0},
PlotRange -> {{-7a0, 7a0}, {0, 1.35}},
PlotLegends-> "Expressions",
Ticks -> {Table[{k a0, Style[If[k > -8, Row[{k, Subscript[a, 0]}], Subscript[a, 0]],
Small]},
{k, -7, 7}], Automatic}]
Plot
's argument (presumablyx
); the optionPlotRange
serves a different purpose, check the documentation, you do not need to use the assignment operator inside plot (just specify the expression you want to plot), defining functions the way you did is generally bad practice (z1[x_] = ...
would be better, so thatx
is explicitly an argument ofPlot
. Read the error message! You supplied plot with 1 argument -- the expression, you didn't give the 2nd argument: the variable and its limits. VTC as "simple mistake". $\endgroup$ – LLlAMnYP Jun 2 '17 at 8:28Plot
. Try it with a simpler example first. $\endgroup$ – LLlAMnYP Jun 2 '17 at 8:29pi
is undefined. Mathematica's symbol names are case-sensitive, you're looking for the built-inPi
. $\endgroup$ – LLlAMnYP Jun 2 '17 at 8:31