Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1991
*January
*February
*March
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1991

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Bug in StruveH

  • To: mathgroup at yoda.ncsa.uiuc.edu
  • Subject: Re: Bug in StruveH
  • From: Steve Christensen <stevec at yoda.ncsa.uiuc.edu>
  • Date: Sun, 10 Feb 91 18:07:20 +0100

pjanhune at finsun.csc.fi writes:

> The package StruveH.m from the book by Roman Maeder contains the
> following bug:
> 
> When called with an integer or rational second argument, the function
> StruveH returns an exact-looking result, which is WRONG!! It's only
> the first term of the series expansion. For floating-point arguments
> or complex numbers the function behaves correctly. One cure is to insert
> the line
> ....

There is indeed a bug in the numerical code of Struve[].
It should not be called with an exact second argument.
Therefore the rule should be made conditional as follows:

(* numerical evaluation *)

StruveH[nu_?NumberQ, z_?NumberQ] :=
	Block[{s=0, so=-1, m=0, prec = Precision[z], 
	        z2 = -(z/2)^2,k1 = 3/2, k2 = nu + 3/2, g1, g2, zf},
		zf = (z/2)^(nu+1); g1 = Gamma[k1]; g2 = Gamma[k2];
		While[so != s,
			so = s; s += N[zf/g1/g2, prec];
			g1 *= k1; g2 *= k2; zf *= z2;
			k1++; k2++; m++
		];
		s
	] /; Precision[z] < Infinity

(The proposed fix by pjanhune at finsun.csc.fi has the disadvantage
of giving an inexact result for exact input. This is contrary to
Mathematica's philosophy. One should use N[StruveH[...]] for this.)

This has already been fixed for the second edition of my book.
All the packages from the book will be part of Mathematica 2.0.

Roman Maeder


  • Prev by Date: Data Help
  • Next by Date: RE: Solve
  • Previous by thread: Re: Data Help
  • Next by thread: Subscripted