1
$\begingroup$

I would like to be able to Plot a function (with an implicit Integrate command) with various values for a certain parameter (phi in the code below for values 0.01 and 0.02) all on the same Plot to compare.Below is my code:

e = 1.60217657*10^-19;
n = 10^-9/e;
R = 1.5;
sigma = 50*10^-6;
p = (R*phi^3)/(24 sigma);
g = D[Exp[-((curlEprime)^2/2)], curlEprime];

G = p^(-(1/3)) (Exp[-((curlE - p)^2/2)] - Exp[-((curlE - 4 p)^2/2)]) +
Integrate[1/(curlE - curlEprime)^(1/3) g, {curlEprime, curlE - p, curlE}];

de = (2 e^2 n)/(3^(1/3) Sqrt[2 Pi] R^(2/3) sigma^(4/3)) G

Plot[de, {curlE, -10, 10}] /. phi -> {0.01, 0.02}
$\endgroup$
3
  • $\begingroup$ Define all your variable depending on phi as var[phi_]:=. Then Plot[de[phi],...] should work. $\endgroup$
    – Öskå
    Commented Apr 29, 2014 at 22:01
  • $\begingroup$ Thanks for the reply. tried it but no luck :/ $\endgroup$ Commented Apr 29, 2014 at 22:19
  • 1
    $\begingroup$ You need p[phi_], g[curlEPrime_], G[phi_, curlE_, curlEprime_] and de[phi_, curlE_, curlEprime_]. I haven't looked in the details so I might be wrong about curlEprime but here is the idea. Then you will be able to plot Plot[de[#,..] /@ {0.01, 0.02},...]. $\endgroup$
    – Öskå
    Commented Apr 29, 2014 at 23:00

1 Answer 1

3
$\begingroup$

Below you'll find a slightly changed version of your code (note the new definition of g - saves some space). Basically, as Öskå wrote in his comments above, you need to define functions of phi, curlEprime and curlE. Also, it seems that the integral could not be derived in a symbolic way.

Furthermore, you should not name your variable with capital letters (see here), hence the small changes bellow:

e = 1.60217657*10^-19;
n = 10^-9/e;
r = 1.5;
sigma = 50*10^-6;
p[phi_] := (r*phi^3)/(24 sigma);
g[curlEprime_] := Exp[-((curlEprime)^2/2)];

gSomething[phi_, curlE_] := With[{p = p[phi]}, 
  p^(-(1/3)) (g[curlE - p] - g[curlE - 4 p]) + 
  NIntegrate[1/(curlE - curlEprime)^(1/3)  g'[curlEprime], 
    {curlEprime, curlE - p, curlE}]]

de[phi_, curlE_] := (2*e^2*n)/(3^(1/3)*
  Sqrt[2 Pi]*r^(2/3)*sigma^(4/3))*gSomething[phi, curlE]

phi = {.01, .02};
Quiet@Plot[de[#, curlE] & /@ phi, {curlE, -10, 10}, 
  PlotRange -> All, Evaluated -> True, PlotLegends -> ToString /@ phi]

enter image description here

$\endgroup$
3
  • 2
    $\begingroup$ I added the Plot and a comment about Capital letters, if you mind feel free to reverse the edit. Plus, if you are on V9 please add PlotLegends -> ToString /@ phi and update the image :) $\endgroup$
    – Öskå
    Commented Apr 30, 2014 at 9:37
  • $\begingroup$ Done, thank you! $\endgroup$ Commented Apr 30, 2014 at 9:52
  • $\begingroup$ WOW! Thank you so much. First of all, the code ran super fast (mine took about 5-10 minutes) and second of all the plots are beautiful (varied phi from 0.01 to 0.11)! $\endgroup$ Commented Apr 30, 2014 at 20:09

Your Answer

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

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