# Renyi dimension

I am trying to plot the Renyi dimension.

I have found a package in the book of Baumann — Mathematica for Theoretical Physics II. The problem is that the code does not work.

I want to plot the $D_q$. I tried with the code reported below.

Dq[p_List, r_List] :=
Block[{l1, l2, listrg = {}},
(*----length of the lists---*)l1 = Length[p];
l2 = Length[r];
If[l1 == l2,
(*----variation of q and determination of D_q---*)
Do[
gl1 = Sum[p[[j]]^q r[[j]]^((q - l1) Dfractal), {j, 1, 11}] - 1;
result = FindRoot[gl1 == 0, { Dfractal, -3, 3}];
result = -Dfractal /. result;
(*----collect the results in a list---*)
AppendTo[listrg, {q, result}],
{q, -10, 10, .101}],
Print[" "];
Print[" Lengths of lists are different!" ];
listrg = {}];
listrg]

ListDq = Dq[p, r];
ListPlot[listDq, AxesLabel {"q", "Dq"}]


I can specify values for p and r. For instance p = {1/5, 3/5, 1/5} and r = {1/2, 1/2, 1/2}.

The problem is probably to set the values of p and r. They should be the probabilities and the size of the boxes. Any ideas?

• We can not help you at all without the code and the description of the problem. – Johu Jul 28 '18 at 22:03
• Are you trying to do the same, as in this question? Measuring fractal dimension of natural objects from digital images – Johu Jul 28 '18 at 22:05
• Looking at the code I transferred to this question from yout answer post, it won't work because you have specified that 'p and r must have length 11 and your example p and r are too short. – m_goldberg Jul 29 '18 at 4:47
• Too short? Why? How can I change it? – Spook82 Jul 29 '18 at 7:32
• @Spook82 you are doing Sum[p[[j]]^q r[[j]]^((q - l1) Dfractal), {j, 1, 11}] the index j goes from 1 to 11 and p and r have only 3 items. BTW, Welcome to Mma.SE. Start by taking the tour now and learning about asking and what's on-topic. Always edit the question if improvable, don't add to the question in the comments or the answers section. By doing all this you help us to help you and likely you will inspire great answers. The site depends on participation, as you receive give back . – rhermans Jul 29 '18 at 9:15

Slightly debugged code.

Dq[p_List, r_List] :=
Block[{l1, l2, listrg = {}},(*----length of the lists---*)
l1 = Length[p];
l2 = Length[r];
If[l1 == l2,(*----variation of q and determination of D_q---*)
Do[
gl1 =
Sum[p[[j]]^q r[[j]]^((q - l1) Dfractal), {j, 1, l1}] - 1;
result = FindRoot[gl1 == 0, {Dfractal, -3, 3}];
result = -Dfractal /. result;
(*----collect the results in a list---*)

AppendTo[listrg, {q, result}]
, {q, -10, 10, .101}],
Print[" "];
Print[" Lengths of lists are different!"];
listrg = {}];
listrg]

p = {1/5, 3/5, 1/5};
r = {1/2, 1/2, 1/2};
ListDq = Dq[p, r];
ListPlot[ListDq, AxesLabel -> {"q", "Dq"}]

• Thanks. It works. Do you know how to exclude a point in ListLinePlo[]t? In this case Exclusions does not work. I would like to exclude the point q=1 where there is a singularity. – Spook82 Jul 29 '18 at 12:23
• See Drop or Delete? – Henrik Schumacher Jul 29 '18 at 13:16
• The modification of the code implies several mathematical problems. The plot is no longer Dq. It looks like that you cannot change $l1$ with $Min[Length[p], Length[r]]$. Any idea? – Spook82 Jul 29 '18 at 18:39
• Sorry, I was a bit in a hurry when I wrote that. I just wanted to point out that you used the number 11 (eleven) where it should have been something dependend on the length of the input data (e.g. l1` ("ell" "one"). – Henrik Schumacher Jul 29 '18 at 18:54