# Why the plot of same function is different in Mathematica and MATLAB

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:

and the plot given by MATLAB is:

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;



• which version are you using? on 11.3 I get similar plot as Matlab. !Mathematica graphics – Nasser Mar 25 '18 at 7:08
• Mine is Mathematica 11.0. Did you use the same code, that I used?? Or did you made any changes – Hari Krishnan Mar 25 '18 at 11:39
• @Nasser If you see the plot that you got have almost the same shape, but both axes are totally different??? – Hari Krishnan Mar 25 '18 at 11:48
• 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. – bill s Mar 25 '18 at 12:50
• I see the problem in v11.0.0.0 but not in v11.0.1.0 Recommend that you download v11.0.1.0 – Bob Hanlon Mar 25 '18 at 17:55

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;

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


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]


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

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.

• 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. – yarchik May 27 '18 at 4:10
• 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 – Hari Krishnan May 28 '18 at 3:57