MathGroup Archive 2002

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

Search the Archive

Re: "a[A_,B_] :=" Does not assign variables properly. Why?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36151] Re: [mg36141] "a[A_,B_] :=" Does not assign variables properly. Why?
  • From: BobHanlon at aol.com
  • Date: Fri, 23 Aug 2002 21:34:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 8/23/02 1:16:57 AM, jwelter at sawtek.com writes:

>Here's a piece of a conversion I had with Mathematica.
>Why is "a[A_,B_] := LinearSolve[X,Y][[1]]" not giving
>me the function I expect?
>
>In[261]:= X = {{0,0,0,1},{1,0,0,1},{0,1,0,1},{1,1,1,1}};
>In[262]:= Y = {A,B,C,D};
>In[263]:= LinearSolve[X,Y]
>Out[263]= {-A+B,-A+C,A-B-C+D,A}
>In[264]:= LinearSolve[X,Y][[1]]
>Out[264]= -A+B
>In[265]:= a[A_,B_] := LinearSolve[X,Y][[1]]
>In[266]:= a[1,3]
>Out[266]= -A+B
>
>The output above is not what I want.  I want "2".  Here's
>what I expect:
>
>In[267]:= a[A_,B_] := -A+B;
>In[268]:= a[1,3]
>Out[268]= 2
>
>This output is what I expect.  What is the difference between
>the two?

X={{0,0,0,1},{1,0,0,1},
      {0,1,0,1},{1,1,1,1}};

Y={A,B,C,D};

a[A_,B_]:=
    LinearSolve[X,Y][[1]];

?a

Global`a

a[A_, B_] := LinearSolve[X,Y][[1]]

Note that the RHS of the stored definition is not a 
function of the arguments.  Now add Evaluate to RHS

a[A_,B_]:=
    Evaluate[LinearSolve[X,Y][[1]]];

?a

Global`a

a[A_, B_] := -A + B

a[1,3]

2


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: MathLink for Excel (Windows 2000, Office 2000 and Mathematica 4.2
  • Next by Date: Re: NDSolve with integral equation
  • Previous by thread: "a[A_,B_] :=" Does not assign variables properly. Why?
  • Next by thread: Re: "a[A_,B_] :=" Does not assign variables properly. Why?