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

MathGroup Archive 2007

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

Search the Archive

Re: How to change symbolic values to numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77103] Re: How to change symbolic values to numbers
  • From: Szabolcs <szhorvat at gmail.com>
  • Date: Sun, 3 Jun 2007 06:17:22 -0400 (EDT)
  • Organization: University of Bergen
  • References: <f3of5j$oq2$1@smc.vnet.net> <f3r8qf$r6i$1@smc.vnet.net>

Jean-Marc Gulliet wrote:
> krzysztof.lisowski at wp.pl wrote:
>> Hello for all.
>> I have a problem with changeing symbolic to number values:
>>
>> f1[{x1_,x2_}]=Block[{},
>> 	L={x1, 1-x1};
>> Print[L]; (*Print prints  {x1, 1-x1} but I want to get value {.5, .
>> 5)*)
>>
>> ];
>>
>> fCE=f1[{x1,x2}]; fC[{x1_, x2_}]=fCE;
>> fCi:=(N[f1[#]])&;
>> fCa=fCi[{.5,.5}];
>> fCa
>>
>> Any help would by very appreciated.
>> With best regards,
>> Krzysztof Lisowski
>>
>>
> 
> Use SetDelayed (:=) rather than Set (=) and define L in your Block 
> statement otherwise it is useless (although Module might be more 
> appropriate here).

WRI should put some scary examples in the documentation about why 
shouldn't one use Block in situations like this.

In[13]:= f1[{L, 1}]

During evaluation of In[13]:= $RecursionLimit::reclim: Recursion \
depth of 256 exceeded. >>

During evaluation of In[13]:= $RecursionLimit::reclim: Recursion \
depth of 256 exceeded. >>

During evaluation of In[13]:= $RecursionLimit::reclim: Recursion \
depth of 256 exceeded. >>

During evaluation of In[13]:= General::stop: Further output of \
$RecursionLimit::reclim will be suppressed during this calculation. \
 >>

Out[13]= $Aborted

Ans this way just a simple and easy to debug example ...

While the documentation does not say that Block is for local variables, 
too many people seem to use it this way when they try to program in a 
procedural style ...

There is no "Possibel issues" section on the doc page, and no mention of 
what can go wrong on
http://reference.wolfram.com/mathematica/tutorial/BlocksComparedWithModules.html

> f1[{x1_, x2_}] := Block[{L}, L = {x1, 1 - x1}; Print[L]; ];
> f1[{0.5, 2.}]
> 
> {0.5, 0.5}
> 
> Regards,
> Jean-Marc
> 


  • Prev by Date: Re: pure function to generate a list of integrals
  • Next by Date: Re: pure function to generate a list of integrals
  • Previous by thread: Re: How to change symbolic values to numbers
  • Next by thread: Re: Integer Solutions