0
$\begingroup$

I am trying to plot a wavefunction for a 1D Particle in a box. I attached my code below, when I run it, it shows a plot with no lines on it. I am new to mathematica, so I am not sure what I am doing wrong.

    a = 30
    f[x_] := Sqrt[2/a]*((3/5)*sin ((2*\[Pi]*x)/a) + (4/5)*(sin ((9*\[Pi]*x)/a)))
    Plot[f[x], {x, 0, a},AxesLabel->{"x","f(x"},PlotStyle->{Black,Dashed}]

I have attached an image of the output. enter image description here

$\endgroup$
  • 3
    $\begingroup$ Welcome to MSE. All WL built-in functions start with an upper case letter. sin should be Sin. Arguments are enclosed in [ ] not ( ). Sin[...]. $\endgroup$ – Rohit Namjoshi Oct 7 '19 at 13:14
  • $\begingroup$ Hey Molly, this is a typical problem for beginners in Mathematica. Nothing to be ashamed of whatsoever. However, I vote to close this thread, because it is just a syntax error and because this is our clean-up policy. Nothing personal. Your input is still welcome on this site. Have fun learning this new language! $\endgroup$ – Henrik Schumacher Oct 7 '19 at 13:43
  • $\begingroup$ And you really should: (1) get rid of all the unnecessary * signs for multiplication: 2 π x is enough (while a space is needed between π and x, you do not need to insert a space between 2 and π; (2) remove superfluous parentheses, e.g., around the second Sin expression; and (3) put a semicolon after a= 30 unless you have some special reason to create a separate outpu cell with 30 in it. $\endgroup$ – murray Oct 7 '19 at 13:50
4
$\begingroup$
a = 30;
f[x_] := Sqrt[2/a] (3/5 Sin[2 \[Pi] x/a] + 4/5 Sin [(9 \[Pi] x)/a])
Plot[f[x], {x, 0, a}, AxesLabel -> {x, "f(x)"}, 
 PlotStyle -> {Black, Dashed}]

A wave function.

Note that you forgot the closing ) in the AxesLabel expression f(x).

When you actually type the input, you may want to take advantage of the Mathematica front end by typing Esc p Esc (with the escape key) to create the symbol π, or at least use Pi; after all, \[Pi] is a lot to type when you don't need to do so. (Perhaps you did do that; good! If you copy that from a notebook and paste here, you will get \[Pi].)

| improve this answer | |
$\endgroup$

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