3
$\begingroup$

I have the following code:

q := 1.6*10^-19;
me := 9.1*10^-31; (* Free electron rest mass in kg *)
h :=  6.63*10^-34;  (* Reduced Planck's constant in J.s *)
kb := 1.38*10^-23;(* Boltzmann constant in J/K *)
Jschottky[V_, T_] := (2 q*(2 \[Pi] me)^0.5 kb^1.5)/h^2*(0.3)^0.5*
  Exp[-0.18/((kb*T)/q)] (Exp[(q*V)/(kb*T)] - 1);
LogPlot[Abs[Jschottky[V, 77]], {V, -0.5, 0.5}, PlotRange -> All, 
 Frame -> True, 
 FrameLabel -> {"Voltage (V)", 
   "\!\(\*FractionBox[\(J\), SuperscriptBox[\(T\), \(3/2\)]]\)"}, 
 BaseStyle -> {FontSize -> 15}, PlotStyle -> {Thick, Red} , 
 AspectRatio -> GoldenRatio, ImageSize -> 400, FrameStyle -> Black, 
 FrameTicks -> {{{#, Superscript[10, Log10@#]} & /@ ({10^-21, 10^-11, 
       10^-1, 10^9, 10^19}), None}, {Automatic, None}}]

Plot[Abs[Jschottky[V, 77]], {V, -0.5, 0.5}, PlotRange -> All, 
 Frame -> True, 
 FrameLabel -> {"Voltage (V)", 
   "\!\(\*FractionBox[\(J\), SuperscriptBox[\(T\), \(3/2\)]]\)"}, 
 BaseStyle -> {FontSize -> 15}, PlotStyle -> {Thick, Blue} , 
 AspectRatio -> GoldenRatio, ImageSize -> 400, FrameStyle -> Black]

I get the following results:

enter image description here enter image description here

Now I want to plot them on the same plot with the logplot on the left y axis and the linear plot on the right yaxis. What should I do? Also any recommendations for a good grayscale plot of the same?

$\endgroup$
3
  • $\begingroup$ Please supply the definition for your Jschottky function. Without it, it is impossible to work with code. $\endgroup$
    – m_goldberg
    Sep 26, 2020 at 18:00
  • $\begingroup$ Sorry, I don't know how I missed that. I have added it. Any help is appreciated. $\endgroup$ Sep 26, 2020 at 20:57
  • $\begingroup$ You probably do not want to use SetDelayed (:=) for your constant values here. You can simply use Set (=). This will avoid unnecessary evaluation time. $\endgroup$ Feb 25, 2021 at 19:12

2 Answers 2

5
$\begingroup$
q := 1.6*10^-19;
me := 9.1*10^-31;(*Free electron rest mass in kg*)h := 
 6.63*10^-34;(*Reduced Planck's constant in J.s*)kb := 
 1.38*10^-23;(*Boltzmann constant in J/K*)
Jschottky[V_, T_] := (2 q*(2 \[Pi] me)^0.5 kb^1.5)/h^2*(0.3)^0.5*
  Exp[-0.18/((kb*T)/q)] (Exp[(q*V)/(kb*T)] - 1);
p1 = LogPlot[Abs[Jschottky[V, 77]], {V, -0.5, 0.5}, PlotRange -> All, 
  Frame -> True, 
  FrameLabel -> {"Voltage (V)", 
    "\!\(\*FractionBox[\(J\), SuperscriptBox[\(T\), \(3/2\)]]\)"}, 
  BaseStyle -> {FontSize -> 15}, PlotStyle -> {Thick, Red}, 
  AspectRatio -> GoldenRatio, ImageSize -> 400, FrameStyle -> Black, 
  ImagePadding -> {{100, 100}, {80, 80}}, FrameTicksStyle -> Red, 
  FrameTicks -> {{{#, Superscript[10, Log10@#]} & /@ ({10^-21, 10^-11,
         10^-1, 10^9, 10^19}), None}, {Automatic, None}}]

p2 = Plot[Abs[Jschottky[V, 77]], {V, -0.5, 0.5}, PlotRange -> All, 
  Frame -> True, 
  FrameLabel -> {{None, 
     "\!\(\*FractionBox[\(J\), SuperscriptBox[\(T\), \(3/2\)]]\)"}, \
{None, None}}, BaseStyle -> {FontSize -> 15}, 
  PlotStyle -> {Thick, Blue}, AspectRatio -> GoldenRatio, 
  ImageSize -> 400, ImagePadding -> {{100, 100}, {80, 80}}, 
  FrameStyle -> Black, FrameTicks -> {{None, All}, {None, None}}, 
  FrameTicksStyle -> Blue]
Overlay[{p1, p2}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks! How should I make the x-axis to be black in color? $\endgroup$ Sep 27, 2020 at 14:04
  • $\begingroup$ For p1, use FrameTicksStyle -> {{Red, None}, {None, Black}}. This sets the color for {{left,right},{top,bottom}}. $\endgroup$ Sep 27, 2020 at 14:14
1
$\begingroup$

On a side note (but too big to fit in a comment), you can speed up the Jschottky function evaluation by about 13x by using FunctionCompile:

f = Function[{Typed[V, "Real64"], Typed[T, "Integer64"]},
  Module[{q, me, h, kb},
   q = 1.6*10^-19;
   me = 9.1*10^-31;
   h = 6.63*10^-34;
   kb = 1.38*10^-23;
   (2 q*(2 \[Pi] me)^0.5 kb^1.5)/h^2*(0.3)^0.5*
    Exp[-0.18/((kb*T)/q)] (Exp[(q*V)/(kb*T)] - 1)
   ]
  ]

and then:

cf = FunctionCompile[f]

On my machine I get the following timings:

In[.]:= Do[Jschottky[RandomReal[{-0.5, 0.5}], 77], 100000] // AbsoluteTiming
Out[.]= {0.777224, Null}

In[.]:= Do[cf[RandomReal[{-0.5, 0.5}], 77], 100000] // AbsoluteTiming

Out[.]= {0.0563924, Null}
$\endgroup$
2
  • $\begingroup$ Thank you, what all functions does it work for? And what are you actually doing by executing it this way? $\endgroup$ Feb 26, 2021 at 16:07
  • $\begingroup$ Almost everything I know is contained in this presentation by Tom Wickham-Jones. It's worth watching! youtube.com/watch?v=LulZszTJH4g $\endgroup$ Feb 26, 2021 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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