MathGroup Archive 1999

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

Search the Archive

Re: RE: Re: Function evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17628] Re: [mg17613] RE: [mg17605] Re: [mg17550] Function evaluation
  • From: BobHanlon at aol.com
  • Date: Fri, 21 May 1999 03:37:27 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Ted,

Using your definition of the function

f[0,_]=0;

f[s_,n_]:=BesselK[0,n*(1-s)]-BesselK[0,n]*BesselI[0,n*(1-s)]/BesselI[0,n];

Table[f[0., n], {n, 0.01, 1.0, 0.01}]

{0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 2.220446049250313*^-16, 0., 0., 0., 
  1.110223024625156*^-16, 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  1.110223024625156*^-16, 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 5.551115123125782*^-17, 0., 0., 0., 0., 0.}

Note by the presence of non-zero values that your definition is not applied 
if the value of the first argument is entered as the real number zero, i.e., 
0. vice 0

A definition should not be so fragile as to depend on whether a value is 
entered 
in its real or exact (e.g., integer or rational) form.

This is a common problem when handling special values of functions.  
Therefore, I make a habit of always using a test of the form s==0 or x==1/2   
to handle special cases for the parameters or arguments.  This works whether  
the argument is entered as an exact number or real.

Consequently, I would still recommend

f[s_/; s==0,n_]:=0;

The unnecessary use of the n, i.e., n_ vice _, is just a personal preference.

Bob Hanlon

In a message dated 5/18/99 7:11:14 AM, ErsekTR at navair.navy.mil writes:

>I thought Bob would have done better.  The following is much simpler, and
>more efficient.
>Regards,
>Ted Ersek
>--------------------
>
>f[0,_]=0;
>
>f[s_,n_]:=BesselK[0,n*(1-s)]-BesselK[0,n]*BesselI[0,n*(1-s)]/BesselI[0,n];
>
>--------------------
>
>>I have a function defined as
>>
>>f[s_,n_]:=BesselK[0,n*(1-s)]-BesselK[0,n]*BesselI[0,n*(1-s)]/BesselI[0,n]
>>
>>We can see that at s=0, f is zero. but mathematica returns a small number,
>>i think it is the workingprecision. I have tried to change the working
>>precision, but that does not help. the function still evaluates to a
>>10^-16 number. I am using this function to define other functions. Ccan
>>someone help me find a way to evaluate this function correctly.
>>
>
>
>Bob Hnlon's solutionn was:
>---------------
>
>Handle the case for s==0 separately:
>
>f[s_/; s==0,n_]:=0;
>
>f[s_,n_]:=BesselK[0,n*(1-s)]-BesselK[0,n]*BesselI[0,n*(1-s)]/BesselI[0,n];
>


  • Prev by Date: Re: Re: Function evaluation
  • Next by Date: Exporting results from Mathematica to other applications
  • Previous by thread: Re: Re: Function evaluation
  • Next by thread: MapOverColumn[f_,mat_?MatrixQ,n_Integer]:= ....