MathGroup Archive 2005

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

Search the Archive

Re: Confusing results with N[expr]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62361] Re: Confusing results with N[expr]?
  • From: Peter Pein <petsie at dordos.net>
  • Date: Tue, 22 Nov 2005 04:42:02 -0500 (EST)
  • References: <dlp320$1bs$1@smc.vnet.net> <dls4su$mlh$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Peter Pein schrieb:
> Thomas Bohl schrieb:
>> I have the impression that since some time (since Vers. 5.0?) N[expr] does 
>> not give anymore the results I expect.
>>
>> The following code should illustrate this:
>>
>> N[a] = 2.;
>>
>> k = z*(a*Pi);
>> N[k]
>>> 6.28319 z       (* "a" and "Pi" are replaced by their numerical value as 
>>> expected *)
>> k = z^(a*Pi)
>> N[k]
>>> z^(3.14159 a)    (* "Pi" is replaced by its numerical value but not "a", 
>>> why not? *)
>>
>> There are more examples of this behaviour: If the expression is Log[z*a*Pi], 
>> the numerical values of "a" and "Pi" are evaluated, if the expression is 
>> Exp[z*a*Pi] the numerical value of "a" is not evaluated. Why not?
>>
>> The motivation behind my question is that I was used to write expressions 
>> symbolically and assign numerical values with N[expr] = num. value. This way 
>> you could keep those expressions symbolically and just apply //N when you 
>> needed numerical values. Now it seems that I have lost this possibility.
>>
>> Could you please comment my observation and maybe suggest a way out?
>>
>> Thank you very much for any idea.
>>
>> Kind regards,
>> Thomas.
>>
>>
> Hi Thomas,
> 
> that's really strange. The reason seems to be Power[]:
> 
> N /@ k
>  > z^(6.283185307179586*x)
> 
> but when I tried
> 
> Unprotect[Power];
> Power /: N[p_Power] := N /@ p;
> Protect[Power];
> 
> the kernel died at the evaluation of N[k].
> 
> The best I have to offer is in the moment:
> 
> 1.) use "N //@ expr" to evaluate a in Exp[Exp[a Pi]]
> or
> 2.)
> Unprotect[Power];
> Power /: N[(x_)^(y_)] := Pow$[N[x], N[y]];
> Protect[Power];
> $Post = #1 /. Pow$ -> Power & ;
> 
> Regards,
>    Peter
> 

Andrzeij pointed out that Solve[N[x2 - 1 == 0], x] and even 
Plot[1,{x,0,1}] do not work any more as expected when using "2.)" above.

Well it seems, I tried to cure a mosquito bite by amputation...

I am sorry,
  Peter


  • Prev by Date: Re: Types in Mathematica
  • Next by Date: Boolean Integral
  • Previous by thread: Re: Re: Confusing results with N[expr]?
  • Next by thread: Re: Confusing results with N[expr]?