Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg30567] Re: Collecting multiple function arguments into a List?
  • From: aes <siegman at stanford.edu>
  • Date: Wed, 29 Aug 2001 01:40:12 -0400 (EDT)
  • Organization: Stanford University
  • References: <9mfmjm$24n$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Yes, this will work, and do what I want to accomplish -- except I think 
you want to write

   vars := {x1, x2, x3}

(delayed assignment), so that  you'll use the current (latest) values of 
x1, x2 each time you call f1[vars].

The problem now is that the function definitions become much harder to 
read (and write).

   --AES

In article <9mfmjm$24n$1 at smc.vnet.net>, "Harvey P. Dale" <hpd1 at nyu.edu> 
wrote:

> 	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:	 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: How do I script the evaluation of a Notebook
  • Next by Date: Re: Mathematica to PDF (and PDF v. PowerPoint)
  • Previous by thread: RE: Collecting multiple function arguments into a List?
  • Next by thread: extra vertical lines showing up in plots