| Author |
Comment/Response |
Forum Moderator
email me
 |
11/02/02 4:04pm
This is an evaluation issue. If you drop the
semi-colon in your definition, you will see
the following:
In[17]:=
F[n_]=Table[
If[i\[NotEqual]n&&i\[Equal]j,1,If[i>j||j\[Equal]n,(-1)^(i+j-1),0]],{i,1,
3},{j,1,3}]
Out[17]=
{{If[1 != n, 1, If[i > j || j == n, (-1)^(i + j - 1),
0]], If[2 == n, (-1)^(i + j - 1), 0],
If[3 == n, (-1)^(i + j - 1), 0]},
{1, If[2 != n, 1, If[i > j || j == n, (-1)^(i + j - 1),
0]], If[3 == n, (-1)^(i + j - 1), 0]},
{-1, 1, If[3 != n, 1, If[i > j || j == n,
(-1)^(i + j - 1), 0]]}}
My guess is that since n is not known, the
evaluation of the expressions that contain n
is not carried out. I'd look further into it,
but this is easy to resolve using SetDelayed
(written := )
In[20]:= Clear[F]
In[21]:=
F[n_]:=Table[
If[Evaluate[i\[NotEqual]n&&i\[Equal]j],1,
If[Evaluate[i>j||j\[Equal]n],(-1)^(i+j-1),0]],{i,1,3},{j,1,3}]
In[22]:= F[3]
Out[22]= {{1,0,-1},{1,1,1},{-1,1,-1}}
There are various articles on evaluation, Set
and SetDelayed in the Help Browser
URL: , |
|