MathGroup Archive 2006

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

Search the Archive

Re: Subscripted variables and function definitions

  • To: mathgroup at
  • Subject: [mg65196] Re: Subscripted variables and function definitions
  • From: dh <dh at>
  • Date: Fri, 17 Mar 2006 05:45:35 -0500 (EST)
  • References: <dvdida$a26$>
  • Sender: owner-wri-mathgroup at

Hi Geico,
I think Mathematica would be much less irritating to you if you would 
first read the book.
See below.

Geico Caveman wrote:
> Hi
> I am trying to define a function (using the front end - I will be using
> latex syntax in this post to make clear what I am doing) :
> A[k_s_,r_t_,r_k_]:=...
If you write r_t_ you are requesting a product of 2 factors. Obvioulsy 
"1" does not meet this criteria (to test you may use: MatchQ[1, x_y_]).
> Now after this, if I try to output A[1,1,1], it just throws A[1,1,1] back.
> However, if I define :
> A[ks_,rt_,rk_]:=...
> it gives the right answer. Two questions :
> 1. Why aren't subscripted variable names treated the same as other variable
> names in this context ?
> 2. Is there a way to coax Mathematica into doing what I am trying to do
> above ?
What you request is, that a pattern of 2 factors match 1 factor. Well, 
this can be done be specifying a default value for one of the factors by 
either "x_.": this says that if can not be matched the pattern matcher 
should try again by replacing x by the global default for multiplication 
  of "1"
or "x_:n": here you are specifying the default value of n explicitely
> Mathematica is a nice system, but it has these highly irritating quirks.
Hi, make a better one!!!
> Another (unrelated) question :
> I have a 4x4 matrix which is a function of some variables :
> A:=... (function of r1,r2,r3, ...)
> f:=... (function of the same variables)
> X:=Inverse[A] . f
> Now, I want to extract a ratio :
> X[1]/(X[3]+X[4]) and assign it to a function :
> g[r1_,r2_,r3_]:=X[1]/(X[3]+X[4])
> A test evaluation of g[1,1,1] throws g[1,1,1] back. Makes no sense at all to
> me. What am I missing, and why is Mathematica so unintuitive here ?
I think that your are fooling yourselfe. If you define:
Mathematica will certainly not return g[1,1,1] unevaluated


  • Prev by Date: Re: Subscripted variables and function definitions
  • Next by Date: Re: A Reap Sow question
  • Previous by thread: Re: Subscripted variables and function definitions
  • Next by thread: Re: Subscripted variables and function definitions