Re: How to change symbolic values to numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg77069] Re: How to change symbolic values to numbers
- From: Bill Rowe <readnewsciv at sbcglobal.net>
- Date: Sat, 2 Jun 2007 04:21:43 -0400 (EDT)
On 6/1/07 at 2:40 AM, 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}; This is a rather unusual construction to say the least. Why use Block when there are no local variables declared? >Print[L]; (*Print prints {x1, 1-x1} but I want to get value {.5, . >5)*)]; The problem you are having is due to using Set rather than SetDelayed. With Set ("=") everything is evaluated when you hit shift-return. In this case that means f1 is set to the list supplied as its argument. L is set to {x1, 1-x}. The expression L={x1, 1-x2} is simply not evaluated again later when you use f1. To see this look at the following: In[31]:= Clear[f1]; f1[{x1_, x2_}] = Block[{}, L = {x1, 1 - x1}]; f1[{1, 2}] // Trace Out[33]= {f1({1,2}),{1,1-1},{{-1,-1},1-1,0},{1,0}} Contrast this with: In[34]:= Clear[f1]; f1[{x1_, x2_}] := Block[{}, L = {x1, 1 - x1}]; f1[{1, 2}] // Trace Out[36]= {f1({1,2}),Block[{},L={1,1-1}],{{{{-1,-1},1-1,0},{1,0}},L={1= ,\ 0},{1,0}},{1,0}} Here, the expression L={x1, 1-x2} is evaluated and you get the desired result. Use Set when you want to immediately assign a value to a variable In general, you want to use SetDelayed (":=") for functions not Set ("=") -- To reply via email subtract one hundred and four