Below is my commands on a mathematica script to plot a function. In order to see why the function has issue to be plotted, I have tried to plot the intermediate functions one-by-one. It seems that my line 4 (and/or possibly line 2) is problematic. What am I missing for the plot? Your help is greatly appreciated.

yfunc[M_] := (M /(10^12));

sigmafunc[M_] := (16.9*(yfunc[M])^0.41)/(
  1 + 1.102*(yfunc[M])^0.20 + 6.22*(yfunc[M])^0.333);

xfunc[M_] := 1.686/sigmafunc[M];

Remove[dsigmadM]; dsigmadM[M_] := (Log[10]*10^M)^-1*D[sigmafunc[x], x] //. x -> M;

funcsigma[M_] := 
  0.322*Sqrt[(2*0.707)/\[Pi]]*(1 + (0.707*(xfunc[M])^2)^-0.3)*

dndLogM[M_] := -0.05152*10^12*funcsigma[M]/sigmafunc[M]*dsigmadM[M];

LogLogPlot[dsigmadM, {M, 10^8, 10^16}, PlotRange -> {10^(-10), 10}, 
 GridLines -> Automatic]
  • 1
    $\begingroup$ Try LogPlot[dsigmadM[M], {M, 7, 17}, PlotRange -> {0.0001, 10}, GridLines -> Automatic] and report back. $\endgroup$ – J. M.'s technical difficulties Apr 5 '16 at 0:28
  • $\begingroup$ I have tried that too. It still doesn't work! $\endgroup$ – Benjamin Apr 5 '16 at 0:28
  • $\begingroup$ Ah, then do this: Remove[dsigmadM]; dsigmadM[M_] := (Log[10]*10^M)^-1*sigmafunc'[M]; $\endgroup$ – J. M.'s technical difficulties Apr 5 '16 at 0:30
  • $\begingroup$ Still not working. $\endgroup$ – Benjamin Apr 5 '16 at 0:34
  • 1
    $\begingroup$ Did you try clearing/removing dsigmadM[] (actually all your symbols) before executing that definition? $\endgroup$ – J. M.'s technical difficulties Apr 5 '16 at 0:48

Besides the plot command (as pointed out by J.M.), you also have a problem with the derivative. Here's one way to fix it:

yfunc[M_] := 10^(12 - M);

   M_] := (16.9*(yfunc[M])^0.41)/(1 + 1.102*(yfunc[M])^0.20 + 

xfunc[M_] := 1.686/sigmafunc[M];

dsigmadM[M_] := (Log[10]*10^M)^(-1)*D[sigmafunc[x], x] //. x -> M;

funcsigma[M_] := 
  0.322*Sqrt[(2*0.707)/π]*(1 + (0.707*(xfunc[M])^2)^-0.3)*

dndLogM[M_] := 0.05152*funcsigma[M]/sigmafunc[M]*dsigmadM[M];

Plot[dsigmadM[M], {M, 7, 17}]

enter image description here

| improve this answer | |
  • $\begingroup$ Hi bill, thanks for the advice. It seems that I cannot get LogPlot though. It's weird. $\endgroup$ – Benjamin Apr 5 '16 at 0:44
  • $\begingroup$ The argument of the logarithms is supposed to be positive so that they have legitimate logarithm. Besides LogPlot, I cannot even get the Plot. $\endgroup$ – Benjamin Apr 5 '16 at 0:48
  • $\begingroup$ The reason you can't get LogPlot is because the function takes on negative values. $\endgroup$ – bill s Apr 5 '16 at 0:56
  • $\begingroup$ Thanks everyone for your comments. I had an inconsistency in the definition of one of my intermediate (namely first) function in the script. I had a "-" typo which had resulted in undefined values. However, the main issue was that I should have compensated the factor $10^{12}$ which I had introduced (in a wrong manner) in the first equation. This is now edited as can be seen from the very last definition just before plotting command. But, even if I had those correctly typed, yet I noticed that the comment made by Bill is significant. Thanks for everyone's help. $\endgroup$ – Benjamin Apr 5 '16 at 3:42

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.