MathGroup Archive 1997

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

Search the Archive

Re: Defining a function from first principles

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9868] Re: [mg9796] Defining a function from first principles
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Sat, 29 Nov 1997 00:10:57 -0500
  • References: <199711281035.FAA10701@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

[mg9796] Defining a function from first principles Arthur Wasserman
writes


> I have a set S of pairs (a1,b1), (a2,b2), ...(a7,b7) where each  a is a
> monomial in some variables t1,t2,t3 and each  b is a real number and no
> monomial appears twice as an a. So S is (the graph of) a function and
> b=f(a). I want to enter such a function into Mathematica and Maple in
> an elegant way. In Maple when S is small I can define f by hand in a
> procedure using many ifs and elifs:
> f :=proc(x)
> if x=t1 then .23 elif x=t2*t3 then 1.5 elif .....else `Undefined` fi
> end;
> 
> If S is big I would use a for loop. Is there a better way?

Arthur:

S = {{a1,b1}, {a2,b2},{a3,b3}};
Apply[(f[#1]=#2)&,S,{1}];

Check that we have made the definition:

{f[a1],f[a2], f[a3]}

	{b1,b2,b3}
 
Allan Hayes
Mathematica Training and Consulting
Leicester, UK
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 4198


  • Prev by Date: Re: Mathlink with java or VB
  • Next by Date: How do I create a cell or "Dialog Box" that simply states a control loop status?
  • Previous by thread: Defining a function from first principles
  • Next by thread: Beginner's Question