1
$\begingroup$

I am trying to plot t as a function of the variable EE which is itself included in variables I have defined. However, when I attempt to plot the function, it just returns an empty graph. Below is my code. I have also tried it without units but it makes no difference. Thanks in advance.

k = Sqrt[2*m*EE/ℏ^2];
κ = Sqrt[2*m*(-EE)/ℏ^2];
a = Quantity[8, "Angstroms"];
m = Quantity[9.11*10^-31, "Kilograms"];
ℏ = Quantity[1.055*10^-34, "Joules"*"Seconds"];
t[EE_] := Cos[k*a] + 1/2*(κ/k - k/κ)*Sin[k*a];
Plot[t[EE], {EE, 0, 20}]
$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE, KJohn! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Chris K Mar 19 at 13:50
2
$\begingroup$

There are some small issues,

  1. Your values arn't being passed through completely. This can be tested by just passing your values into the function and see if it's fully evaluated.

    t[10]
    

$$\frac{1}{2} \left(\frac{\sqrt{\text{EE} \left(-8.1849\times 10^{37}\text{kg}\text{/(}\text{s}^2\text{J}^2)\right)}}{\sqrt{\text{EE} \left(8.1849\times 10^{37}\text{kg}\text{/(}\text{s}^2\text{J}^2)\right)}}-\frac{\sqrt{\text{EE} \left(8.1849\times 10^{37}\text{kg}\text{/(}\text{s}^2\text{J}^2)\right)}}{\sqrt{\text{EE} \left(-8.1849\times 10^{37}\text{kg}\text{/(}\text{s}^2\text{J}^2)\right)}}\right) \sin \left(\left(8 \sqrt{2}\text{\AA}\right) \sqrt{\text{EE} \left(8.1849\times 10^{37}\text{kg}\text{/(}\text{s}^2\text{J}^2)\right)}\right)+\cos \left(\left(8 \sqrt{2}\text{\AA}\right) \sqrt{\text{EE} \left(8.1849\times 10^{37}\text{kg}\text{/(}\text{s}^2\text{J}^2)\right)}\right)$$

You can see that EE is not passed as 10, this is one of the reasons your plot isn't working.

  1. Plot evaluates t[x] first, before replacing EE.

  2. If you use quantities, your variable must also be a quantity that fits the rest of your function. So seconds, or whatever unit it should be.

  3. And the final issue, your function gives imaginary values, and this cannot be plotted via plot anyways. Unless you want just the imaginary, or real parts.

Table[t[x], {x, 1, 5, 1}]

$$\{0.0558745\, +0.998438 i,-0.551074+0.834456 i,-0.575739+0.817633 i,-0.993756+0.111574 i,0.79168\, -0.610936 i\}$$

This can be plotted if you turn k and κ into functions, and pass them directly the variables from your plot, and use only the Real or Imaginary parts.

k[ee_] := Sqrt[2*m*ee/ℏ^2];
κ[ee_] := Sqrt[2*m*(-ee)/ℏ^2];
a = 8
m = 9.11*10^-31
ℏ = 1.055*10^-34
t[EE_] := Cos[k[EE]*a] + 1/2*(κ[EE]/k[EE] - k[EE]/κ[EE])*Sin[k[EE]*a];

Plot[Re[t[x]], {x, 0, 20}, PlotRange -> All]

plot

Though it's pretty messy.

$\endgroup$

Your Answer

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.