MathGroup Archive 2001

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

Search the Archive

RE: Collecting multiple function arguments into a List?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30536] RE: [mg30519] Collecting multiple function arguments into a List?
  • From: "Harvey P. Dale" <hpd1 at nyu.edu>
  • Date: Tue, 28 Aug 2001 04:54:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

	You can refer to a term in a list by its index.  For example, if
vars = {x1, x2, x3, x4, x5, x6, x7, x8}, then vars[[2]] will produce x2.
	Thus, if you wish a function of x1, x2, and x4 to equal, for
example, 2 x1 + 3 x2 - x4^2, you can define f1[varlist_]:=2 varlist[[1]]+3
varlist[[2]] - varlist[[4]]^2.  Evaluating f1[vars] will then do what you
wish.  You can follow this same process for f2, f3, etc.
	Best,
	Harvey
Professor Harvey P. Dale
Director
National Center on Philanthropy and the Law
New York University School of Law
Room 206A
110 West 3rd Street
New York, N.Y. 10012-1074


 -----Original Message-----
From: 	aes [mailto:siegman at stanford.edu] 
To: mathgroup at smc.vnet.net
Sent:	Friday, August 24, 2001 8:58 PM
To:	mathgroup at smc.vnet.net
Subject:	[mg30519] Collecting multiple function arguments into a
List?

I have a problem with 8 input variables, call 'em  x1, x2, ... , x8, and 
I want to define a bunch of functions (using :=, not =) that depend on 
various subsets of these variables, e.g.

   f1[ x1_, x2_, x4_] :=  << stuff involving x1, x2, x4 >>
   
   f2[ x1_, x3_] :=  << stuff involving  x1 and x3 only >> 
   
   f3[[x2_, x3_, x5_, x8_} := << stuff involving x2, x3, x5, x8 >>

To minimize typing and bookkeeping I'd like to define a list of the 
input variables, e.g.

   vars = {x1, x2, x3, x4, x5, x6, x7, x8}
   
and then write all the function definitions in the simplified syntax

   f1[vars_] := << same stuff as above >>
   f2[vars_] := << same stuff as above >>
   f3[vars_] := << same stuff as above >>
   
Can I do this?  What's the required syntax?

   vars = {x1, x2, x3 ...} ??   OR   vars = {x1_, x2_, x3_} ??
   
   fn[vars] :=  << >> ??   OR   fn[vars_] := << >>??
   
Thanks,  siegman at stanford.edu

_____________________________________________________________________
This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp


  • Prev by Date: Re: Collecting multiple function arguments into a List?
  • Next by Date: Re: How do I script the evaluation of a Notebook
  • Previous by thread: Re: Collecting multiple function arguments into a List?
  • Next by thread: Re: Collecting multiple function arguments into a List?