4
$\begingroup$

I want to compute the value of the radial oblate spheroidal wave function of the second kind. However, I found the value at small arguments (for example $0.5I$ in the following code) cannot be computed and it shows Overflow.

But I can definitely look up the table 15.19 in Zhang's text book [1] that the following result should be $-0.6809057$. Does anyone know why Mathematica can not correctly compute it? Thank you.

Example 1 (failed): Run

N[SpheroidalS2[0, 0, -I , 0.5I]]

or

N[SpheroidalS2[0, 0, -I , 0.5I],10]

The return is

Overflow[]

Example 2 (success): Run

N[SpheroidalS2[0, 0, -I , 5I]]

The return is

-0.06805967763768572

Update

According to @MassDefect's suggestion, I tried the following code

N[SpheroidalS2[0, 0, -I,  I/2], 10]

It works and the result is

-0.6890905746 + 0.*10^-11 I

But if I type

N[SpheroidalS2[0, 0, -I,  I/10], 10]

It still shows

Overflow[]

Updata #2

According to @Bill Watts's answer, one can try different precision and maybe there is no Overflow. For example, if one run

N[SpheroidalS2[0, 0, -I, I/10], 50]

The result will be

-1.13893813158018132761330789352859720024513682988326 + 0.*10^-51 I

This is a good trick. However, it can not solve my problem in two aspects.

Firstly, I tried many precision scheme but it always return Overflow:

N[SpheroidalS2[0, 0, -I, 0], 200]

Secondly, I want a big numerical table for further computations. For example, the argument may begin with $0$ and end with $10 I$ with the step of $0.001I$. The Bill Watts's answer can not be applied because the requirement of the precision is different for different arguments.

[1] Zhang, S., & Jin, J. (1996). Computation of Special Functions. New York: John Wiley & Sons.

$\endgroup$
  • 4
    $\begingroup$ i should be I. $\endgroup$ – xzczd Dec 28 '19 at 8:46
  • $\begingroup$ Thank you for pointing out the typo @xzczd . Because I use [Esc] ii [Esc] in Mathematica which looks like "i", so I typed "i" in the original post. Now I changed it into "I" according to your suggestion. Please note it is not a simple mistake and this thread should not be closed. I added a successful example where the argument "0.5" is changed into "5". $\endgroup$ – Jiaxin Zhong Dec 28 '19 at 22:08
  • $\begingroup$ @xzczd Does it mean the question will not be seen by others if it is closed? $\endgroup$ – Jiaxin Zhong Dec 28 '19 at 22:19
  • 2
    $\begingroup$ When questions are closed they are only viewable by the author and people with at least 3000 reputation. I feel that this question may have been closed prematurely as "i" to "I" didn't fix the issue you were experiencing. However, I think if you provide an explicit number of decimals to N, it avoids machine precision computation and provides a result. N[SpheroidalS2[0, 0, -I, I/2], 10] seems to work for me. Notice that I have to keep the value inside Spheroidal as an exact value to avoid the overflow. $\endgroup$ – MassDefect Dec 28 '19 at 22:34
  • 2
    $\begingroup$ In version 10.1 under Windows 7 x64 N[SpheroidalS2[0, 0, -I, 0.5 I], 10] returns -0.689091 + 0. I and N[SpheroidalS2[0, 0, -I, I/10], 10] returns -1.1389381316 + 0.*10^-11 I. I am tagging this as a regression; please correct me if it is not. $\endgroup$ – Mr.Wizard Dec 29 '19 at 10:09
7
$\begingroup$

Looks like you have to fool around with the precision on a case by case basis.

N[SpheroidalS2[0, 0, -I, I/2]]
(*-0.6890905745631529 + 0.*I*)

works, but

N[SpheroidalS2[0, 0, -I, I/10]]

gets an overflow. However,

N[SpheroidalS2[0, 0, -I, I/10], 50]
-1.13893813158018132761330789352859720024513682988326 + 0.*10^-51 I

works.

In any case, I would always use exact numbers with this function.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Good tricks. However, I tried many precisions like 50, 100, 200 and it is still Overflow if the input is N[SpheroidalS2[0, 0, -I, 0], 50]. I want to generate a big numerical table for further computations so I expect a better solution $\endgroup$ – Jiaxin Zhong Dec 30 '19 at 7:50
  • 1
    $\begingroup$ For that one you get pretty close with N[SpheroidalS2[0, 0, -I, 10^-50], 50], but maybe someone else can come up with a solution that covers all inputs. $\endgroup$ – Bill Watts Dec 30 '19 at 8:10
7
$\begingroup$

Please report this issue to Wolfram support. It seems that LinearSolve has a bug related to the new in M12 handling of machine number underflow. As an example, the following extracts the LinearSolve call that doesn't work in M12, but does in M11.1:

ls = Reap[
    TracePrint[
        SpheroidalS2Prime[0, 0, -I, 0.],
        _LinearSolve,
        TraceInternal->True,
        TraceAction->Sow
    ]
][[2,1,6]]

General::ovfl: Overflow occurred in computation.

General::ovfl: Overflow occurred in computation.

General::ovfl: Overflow occurred in computation.

General::stop: Further output of General::ovfl will be suppressed during this calculation.

enter image description here

In M11.1 the above evaluates without error:

enter image description here

{-2.0000000000000000000000000, 2.6666666666666666666666667, \ -3.200000000000000000000000, 3.657142857142857142857143, \ -4.063492063492063492063492, 4.432900432900432900432900, \ -4.773892773892773892773893, 5.092152292152292152292152, \ -5.391690662278897573015220, 5.675463855030418497910758, \ -5.945724038603295569239842, 6.204233779412134507032878, \ -6.452403130588619887314193, 6.691381024314124327585089, \ -6.922118301014611373363886, 7.145412439757018191859495, \ -7.361940089446624803734025, 7.572281234859385512412140, \ -7.776937484450179715450306, 7.976346137897620220974673, \ -8.170891165651220714169177, 8.360911890433807242405669, \ -8.546709932443447403348018, 8.728554824623095220440529, \ -8.906688596554178796367886, 9.081329549427790145316276, \ -9.252675389983031468812810, 9.420905851619086586427588, \ -9.586184901647491614259651, 9.748662611844906726365747, \ -9.908476753022692082535677, 10.065754161800830052099736, \ -10.220611918136227437516655, 10.373158364675574115688545, \ -10.523493993149133160843451, 10.671712218404754754658148, \ -10.817900057013039066365794, 10.962138724439879587250671, \ -11.104504162419618283188991}

In M12 we get overflow errors:

enter image description here

General::ovfl: Overflow occurred in computation.

General::ovfl: Overflow occurred in computation.

General::ovfl: Overflow occurred in computation.

General::stop: Further output of General::ovfl will be suppressed during this calculation.

{Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[], Overflow[]}

As a workaround, you can override the evaluation of LinearSolve so that it defaults to the slower and less robust method using Inverse:

Unprotect[LinearSolve];
LinearSolve[s1_SparseArray,s2_SparseArray] /; !TrueQ@$LSFlag := Block[{$LSFlag=True},
    Quiet[
        Check[
            LinearSolve[s1,s2],
            Inverse[s1].s2, 
            General::ovfl
        ],
        General::ovfl
    ]
]
Protect[LinearSolve];

Then:

SpheroidalS2[0, 0, -I, .1 I]
SpheroidalS2[0, 0, -I, 0.]

-1.13894 + 0. I

-1.25234 + 0. I

| improve this answer | |
$\endgroup$

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.