0
$\begingroup$

I need to create a log-log plot of the following function:

$$ f_k(v)=\frac{v^2\left[v^2/(k-3/2)+1\right]^{-k}\ \Gamma(k+1)}{k\sqrt{\pi(k-3/2)}\ \Gamma(k-1/2)} $$

And the Mathematica code is

f1=((v^2/(k - 3/2) + 1)^-k Gamma[k + 1] v^2)/(k Sqrt[(k - 3/2) \[Pi]]
  Gamma[k - 0.5])

The plot given by Mathematica is: enter image description here

and the plot given by MATLAB is: enter image description here

What could be the reason for this? Please see the code of Mathematica?

 ClearAll["Global`*"]

 distFunckappa = ((v^2/(k - 3/2) + 1)^-k Gamma[k + 1] v^2)/(
 k Sqrt[(k - 3/2) \[Pi]] Gamma[k - 0.5])



 k = 2;

LogLogPlot[distFunckappa, {v, 0, 10}, 
 PlotStyle -> Directive[Blue, Thick], 
 AxesStyle -> Directive[Black, Bold, FontSize -> 14], 
 TicksStyle -> Directive[Black, Bold], AxesLabel -> {"v", "DNF"}, 
 Axes -> True]

and code in MATLAB is:

k=2;

v=0:0.1:10;

kappaDistFunc=(gamma(k+1)./(k.*gamma(k-1/2).*sqrt(k-3/2).*sqrt(pi))).*(1+(v.^2./(k-3/2))).^(-k).*v.^2;

loglog(kappaDistFunc)

Please help me. Thanks in advance.

$\endgroup$
  • 4
    $\begingroup$ which version are you using? on 11.3 I get similar plot as Matlab. !Mathematica graphics $\endgroup$ – Nasser Mar 25 '18 at 7:08
  • $\begingroup$ Mine is Mathematica 11.0. Did you use the same code, that I used?? Or did you made any changes $\endgroup$ – Hari Krishnan Mar 25 '18 at 11:39
  • $\begingroup$ @Nasser If you see the plot that you got have almost the same shape, but both axes are totally different??? $\endgroup$ – Hari Krishnan Mar 25 '18 at 11:48
  • 2
    $\begingroup$ Your Matlab plot has x-values going from 2 to 100. The Mathematica plot has x-values going from about .01 to 10. If you plot them over the same raneg they will probably look more alike. $\endgroup$ – bill s Mar 25 '18 at 12:50
  • $\begingroup$ I see the problem in v11.0.0.0 but not in v11.0.1.0 Recommend that you download v11.0.1.0 $\endgroup$ – Bob Hanlon Mar 25 '18 at 17:55
4
$\begingroup$

The two plots are not the same because the Matlab code doesn't plot $f_2(v)$ as a function of $v$, but as a function of the vector index.

In the code below I removed the 0 endpoint because in a log axis the 0 cannot be represented.

Matlab

v=0.1:0.1:10;

kappaDistFunc=(gamma(k+1)./(k.*gamma(k-1/2).*sqrt(k-3/2).*sqrt(pi))).*(1+(v.^2./(k-3/2))).^(-k).*v.^2;

loglog(v,kappaDistFunc); % The x-axis now represents v

MAtlab plot

Mathematica

distFunckappa = ((v^2/(k - 3/2) + 1)^-k Gamma[
      k + 1] v^2)/(k Sqrt[(k - 3/2) \[Pi]] Gamma[k - 0.5]);

k = 2;

LogLogPlot[distFunckappa, {v, 0.1, 10}, 
 PlotStyle -> Directive[Blue, Thick], 
 AxesStyle -> Directive[Black, Bold, FontSize -> 14], 
 TicksStyle -> Directive[Black, Bold], AxesLabel -> {"v", "DNF"}, 
 Axes -> True]

enter image description here

$\endgroup$
  • $\begingroup$ Still this code will not work in Mathematica 11.0... $\endgroup$ – Hari Krishnan May 28 '18 at 3:56
0
$\begingroup$

There is a way to plot it correctly.'

distFunckappa = 
  Table[{v, (v^2 (v^2/(k - 3/2) + 1)^-k Gamma[k + 1])/(
    k Sqrt[\[Pi] (k - 3/2)] Gamma[k - 0.5])}, {v, 0, 10, 0.1}];

ListLogLogPlot[distFunckappa, PlotStyle -> Directive[Blue, Thick], 
 AxesStyle -> Directive[Black, Bold, FontSize -> 14], 
 TicksStyle -> Directive[Black, Bold], AxesLabel -> {"v", "DNF"}, 
 Axes -> True]

This way you will get the correct plot. I really dont know, why simple loglog plot doesnt give 'the correct answer.

$\endgroup$
  • $\begingroup$ Would be nice if you explain why simple LogLogPlot does not give you the right result. As for now, you seems to indicate that only one of 2 functions should be used. However, many users (@Nasser) in the comments above have already indicated that they cannot reproduce you first picture, and that actually LogLogPlot gives the correct result. Also, you forgot the definition of k in your answer. $\endgroup$ – yarchik May 27 '18 at 4:10
  • $\begingroup$ I clearly do not know, why simple loglogplot does not give a correct answer. This happens only in Mathematica 11.0. In Mathematica 11.1 the plot comes out correctly. Also the value of k is 2 $\endgroup$ – Hari Krishnan May 28 '18 at 3:57

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.