0
$\begingroup$

I am a physics student and this is my first time working with Mathematica. I am trying to run the notebook mentioned here, titled "Amplification factors of the superradiant scattering of a charged wave off a spherically-symmetric or a slowly-rotating BH with generic metric" by Cardoso, Pani and Brito.

Essentially, I am trying to numerically integrate a differential equation. The section I am having trouble with is the following:

ORDH = 3;
h[r_] := Sum[hh[i] (r - rp)^i, {i, 0, ORDH}]
ruleH = {};
ss = Series[eqSH //. ruleH, {r, rp, ORDH}];
eqsH = Table[SeriesCoefficient[ss, i] == 0, {i, 1, ORDH}]
yh = Table[hh[i], {i, 1, ORDH}]
Length[eqsH]
Length[yh]
seriesH = Solve[eqsH, yh][[1]] // Simplify;
seriesH = Union[seriesH, ruleH]
Clear[h]

eqsH is the expression for a homogenous differential equation in terms of h[r] and it's derivatives. From my understanding, what they are trying to do here, is to expand h[r] as a series about the point rp (which is also defined as a constant value earlier in the program) upto 3rd order. Then eqsH is redefined as a table involving each coefficient of the first to third powers of (r-rp) set individually to zero. yh is just a list containing these coefficients. Since these two lists together make up a linear system of equations in terms of the variables hh[i] this can be solved using the Solve command.

When I run this program it runs until I get the Length of both lists (I get 3 as the output as required). When it begins to solve the equations, it runs indefinitely. In a friend's computer, it took about a minute to run (his computer does have better performance, but my PC ranks quite well in Mathematica's internal benchmarking test). When I try to abort the evaluation I get the following errors:

$RecursionLimit:Recursion depth of 1024 exceeded during evaluation of Union[seriesH,{}]

and

Union: Nonatomic expression expected at position 1 in Union[seriesH,{}]

Regarding the recursion limit I have tried to reset it as follows:

Block[{$RecursionLimit = 10000}, seriesH]

But this changes nothing. I do not understand the other error. How do I resolve this?

$\endgroup$
5
  • 1
    $\begingroup$ You should copy and paste every line. Second line eqSH = eqS /. k -> -kH; is missing $\endgroup$
    – Akku14
    Sep 6 at 17:27
  • $\begingroup$ Yes. That is a constant replacement. I linked the whole notebook because I felt like my post was already too long. While running it, I am running it in order. $\endgroup$
    – newtothis
    Sep 6 at 17:36
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Sep 6 at 17:42
  • $\begingroup$ Can you mention which version of Mathematica you're running and which OS? And which version & OS your friend is using? I'm suspicious is that this is due to a change in how Mathematica behaves between versions. $\endgroup$ Sep 6 at 20:21
  • $\begingroup$ I am running Mathematica 12.3.1 on Windows 10. My friend is running Mathematica 12.1.1 on an M1 MacBook Air. $\endgroup$
    – newtothis
    Sep 7 at 3:20
1
$\begingroup$

The errors you are receiving are because you are aborting the code. If you run the penultimate line of the code,

seriesH = Union[seriesH, ruleH]

on a "clean" kernel (with nothing in memory), you get exactly the same errors. This suggests that the errors arise because you aborting the code before the previous line defines seriesH.

As to why it is taking so long on your machine, I'm not sure. I'll note that even if you set ORDH to 1, the Solve command still seems to take an inordinately long time despite the fact that you're asking it to solve an equation of the form A hh[0] + B hh[1] == 0 for hh[1]. One would think this would be nearly instantaneous, yet here we are.

$\endgroup$
6
  • $\begingroup$ I'm not sure I follow. Are you suggesting that the recursion depth error is also because I am aborting the code? And regarding the time, does it seem to universally take that long? I have already tried it on two different computers, and it seems to be really slow on all the Windows machines I've tried. $\endgroup$
    – newtothis
    Sep 6 at 18:46
  • $\begingroup$ @newtothis: Yes, the recursion depth error is due to aborting the code; I suspect it is unrelated to the slowness of the equation-solving. You could test this by quitting your kernel and then running the code seriesH = {foo}; seriesH = Union[seriesH, ruleH]. If I'm right, then it should return {foo} without errors. (I'd try it myself, but I can't run Mathematica right now.) $\endgroup$ Sep 6 at 20:18
  • $\begingroup$ As far as the amount of time the Solve command takes, I really don't know what's going on there. I ran the code with ORDH = 1 for over an hour on a year-old MacBook Pro and it did not complete. $\endgroup$ Sep 6 at 20:25
  • $\begingroup$ Yeah it returns {foo} but this also takes a very long time. If I abort it, it returns {foo}. I have even tried reinstalling Mathematica, and running this file on WolframCloud. It's the same issue on Wolfram Cloud as well. $\endgroup$
    – newtothis
    Sep 7 at 3:27
  • $\begingroup$ So I installed Mathematica 12.0 instead of 12.3 and now, the code runs and completes in around 5 minutes. So I think that solves the issue. Thanks! $\endgroup$
    – newtothis
    Sep 7 at 6:07

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.