0
$\begingroup$

I have two functions that I want to plot together. I want to plot the non-linear and the linear (NL and L in my code) functions together, but I wish that the NL function is plotted as a series of dots instead of a rigid line. While, each value of the VOLTAGES has a common label and color. The code I have is

T = 298.15(*K*);
k1 = 1.38064852*10^-23 (*J/K*);
\[Epsilon]0 = 8.85418781761*10^-12 (*C^2/N m^2||F/m||C/V m*);
\[Epsilon] = 78.5;
\[Epsilon]R = \[Epsilon] \[Epsilon]0 (*C^2/N m^2||F/m||C/Vm*);
z = 1;
e1 = 1.60217733*10^-19 (*C*);
NA = 6.022140857*10^23 (*mol^-1*);
a = 4.25(*\[Angstrom]*);
a1 = a*10^-10 (*m*);
x1 = x*10^-10 (*m*);
VOLTAGES = {10, 20, 50, 100, 300, 400} (*mV*);
L\[Sigma]MKS[\[Rho]0_, \[Psi]H_, x_] = 
  Piecewise[{{0, 
     0 <= x1 < a1/2}, {\[Epsilon]R Sqrt[(
      2 \[Rho]0 *(10^3) NA (e1^2) (
       z^2) )/(\[Epsilon]R k1 T)] \[Psi]H /
      1000 Exp[\[Kappa]MKS[\[Rho]0] (a1/2 - x1)], 
     x1 >= a1/2}}](*C/m^2*);
NL\[Sigma]MKS[\[Rho]0_, \[Psi]H_, x_] = 
  Piecewise[{{0, 
     0 <= x1 < a1/2}, {(
      4 \[Epsilon]R Sqrt[(
       2 \[Rho]0 *(10^3) NA (e1^2) (z^2) )/(\[Epsilon]R k1 T)] k1 T)/(
       z e1) (((Exp[(z e1 \[Psi]H/1000)/(k1 T)] - 1) Exp[
           Sqrt[(2 \[Rho]0 *(10^3) NA (e1^2) (
             z^2) )/(\[Epsilon]R k1 T)] (a1/2 - x1)])/((Exp[(
             z e1 \[Psi]H/1000)/(2 k1 T)] + 
            1)^2 - ((Exp[(z e1 \[Psi]H/1000)/(2 k1 T)] - 1) Exp[
             Sqrt[(2 \[Rho]0 *(10^3) NA (e1^2) (
               z^2) )/(\[Epsilon]R k1 T)] (a1/2 - x1)])^2)), 
     x1 >= a1/2}}](*C/m^2*);

Currently, I have this code in order to plot each function, however I do not know how to combine them and plot one of them as a series of dots.

Show[{Plot[
   Evaluate@
    Table[NL\[Sigma]MKS[0.001, \[Psi]H, a x], {\[Psi]H, 
      VOLTAGES}], {x, 0, 80}, PlotRange -> {-2.5 10^-4, 0.01}, 
   PlotLegends -> 
    Placed[{"\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=10 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=20 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=50 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=100 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=300 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=400 [mV]"}, {0.85, 
      0.5}]], Graphics[
   Text[Style["\!\(\*SubscriptBox[\(\[Rho]\), \(0\)]\)= 0.001 M", 
     Black, Italic, 15], {40, 8.975 10^-3}]]}, Frame -> True, 
 FrameLabel -> {"x/a", 
   "\[Sigma](x)   [C/\!\(\*SuperscriptBox[\(m\), \(2\)]\)]"}, 
 ImageSize -> Large] 
Show[{Plot[
   Evaluate@
    Table[L\[Sigma]MKS[0.001, \[Psi]H, a x], {\[Psi]H, VOLTAGES}], {x,
     0, 80}, PlotRange -> {-2.5 10^-4, 0.01}, 
   PlotLegends -> 
    Placed[{"\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=10 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=20 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=50 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=100 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=300 [mV]", 
      "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=400 [mV]"}, {0.85, 
      0.5}]], Graphics[
   Text[Style["\!\(\*SubscriptBox[\(\[Rho]\), \(0\)]\)= 0.001 M", 
     Black, Italic, 15], {40, 8.975 10^-3}]]}, Frame -> True, 
 FrameLabel -> {"x/a", 
   "\[Sigma](x)   [C/\!\(\*SuperscriptBox[\(m\), \(2\)]\)]"}, 
 ImageSize -> Large]

Any ideas will be appreciated. Thanks in advance

$\endgroup$
  • $\begingroup$ What is \[Kappa]MKS? $\endgroup$ – MelaGo Apr 17 at 0:59
1
$\begingroup$

You can combine plots using Show.

Since \[Kappa]MKS was not defined, I made a random guess for the definition, for demonstration purposes. I also made a few other adjustments because blue variables inside functions make me nervous.

T = 298.15(*K*);
k1 = 1.38064852*10^-23 (*J/K*);
\[Epsilon]0 = 8.85418781761*10^-12 (*C^2/N m^2||F/m||C/V m*);
\[Epsilon] = 78.5;
\[Epsilon]R = \[Epsilon] \[Epsilon]0 (*C^2/N m^2||F/m||C/Vm*);
z = 1;
e1 = 1.60217733*10^-19 (*C*);
NA = 6.022140857*10^23 (*mol^-1*);
a = 4.25(*\[Angstrom]*);
a1 = a*10^-10 (*m*);
VOLTAGES = {10, 20, 50, 100, 300, 400} (*mV*);

\[Kappa]MKS[\[Rho]0_] := 25 \[Rho]0; (* random guess for definition *)


L\[Sigma]MKS[\[Rho]0_, \[Psi]H_, x_] := 
 Piecewise[{{0, 0 <= x < a1/2}, {\[Epsilon]R Sqrt[(2 \[Rho]0*(10^3) NA (e1^2)(z^2))/(\
\[Epsilon]R k1 T)] \[Psi]H/1000 Exp[\[Kappa]MKS[\[Rho]0] (a1/2 - x)], x >= a1/2}}](*C/m^2*);

NL\[Sigma]MKS[\[Rho]0_, \[Psi]H_, x_] := 
  Piecewise[{{0, 0 <= x < a1/2}, {(4 \[Epsilon]R Sqrt[(2 \[Rho]0*(10^3) NA (e1^2) \
(z^2))/(\[Epsilon]R k1 T)] k1 T)/(z e1) (((Exp[(z e1 \[Psi]H/1000)/(k1 T)] - 1) Exp[Sqrt[(2 \[Rho]0*(10^3) NA (e1^2) (z^2))/(\[Epsilon]R k1 \
T)] (a1/2 - x)])/((Exp[(z e1 \[Psi]H/1000)/(2 k1 T)] + 1)^2 - ((Exp[(z e1 \[Psi]H/1000)/(2 k1 T)] - 1) Exp[Sqrt[(2 \[Rho]0*(10^3) NA (e1^2) (z^2))/(\[Epsilon]R k1 T)] (a1/2 - x)])^2)), x >= a1/2}}](*C/m^2*);

You can sample the NL\[Sigma]MKS function with

samples = Table[{#, NL\[Sigma]MKS[0.001, \[Psi]H, a # 10^-10]} & /@ 
    Range[1, 80, 2], {\[Psi]H, VOLTAGES}];

or

samples = Table[Table[{x, NL\[Sigma]MKS[0.001, \[Psi]H, a x 10^-10]}, {x, 1, 
     80, 2}], {\[Psi]H, VOLTAGES}];

Then make the plots and combine with Show.

p1 = Show[{ListPlot[samples, PlotRange -> {-2.5 10^-4, 0.01}, 
     PlotLegends -> 
      Placed[{"\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=10 [mV]", 
        "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=20 [mV]", 
        "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=50 [mV]", 
        "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=100 [mV]", 
        "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=300 [mV]", 
        "\!\(\*SubscriptBox[\(\[Psi]\), \(H\)]\)=400 [mV]"}, {0.85, 
        0.5}]], Graphics[
     Text[Style["\!\(\*SubscriptBox[\(\[Rho]\), \(0\)]\)= 0.001 M", 
       Black, Italic, 15], {40, 8.975 10^-3}]]}, Frame -> True, 
   FrameLabel -> {"x/a", 
     "\[Sigma](x)   [C/\!\(\*SuperscriptBox[\(m\), \(2\)]\)]"}, 
   ImageSize -> Large];
p2 = Plot[
   Evaluate@
    Table[L\[Sigma]MKS[0.001, \[Psi]H, a x], {\[Psi]H, VOLTAGES}], {x,
     0, 80}, PlotRange -> {-2.5 10^-4, 0.01}];

Show[p1, p2]

enter image description here

$\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.