Defining a function from first principles
- To: mathgroup at smc.vnet.net
- Subject: [mg9796] Defining a function from first principles
- From: Arthur Wasserman <awass at math.lsa.umich.edu>
- Date: Fri, 28 Nov 1997 05:35:10 -0500
- Organization: University of Michigan ITD News Server
- Sender: owner-wri-mathgroup at wolfram.com
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? In Mathematica I could say f[t1]= .23, etc. but I should be able to do better. I tried f[a_]:= b/;MemberQ[S,{a,b}] but that did not work. Any suggestions? I am really interested in the case when S is large; the above are toy versions of the problem. Thanks.
- Follow-Ups:
- Re: Defining a function from first principles
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Re: Defining a function from first principles