RE: functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg45507] RE: [mg45481] functions*From*: "David Park" <djmp at earthlink.net>*Date*: Sat, 10 Jan 2004 16:43:27 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

Laurence, The second function is not too difficult. f[n_?OddQ] := 1/n f[n_?EvenQ] := n tab = Table[f[n], {n, 1, 20}] {1, 2, 1/3, 4, 1/5, 6, 1/7, 8, 1/9, 10, 1/11, 12, 1/13, 14, 1/15, 16, 1/17, 18,1/19, 20} We could plot the results using Log for a more balanced picture. ListPlot[Log[tab], Prolog -> AbsolutePointSize[4]]; For non-integers the function is undefined and we just get the input back. f[3.5] f[3.5] But I don't think there is a similar solution within Mathematica for your first case . The problem is how can you feed a general irrational value to Mathematica in a way that Mathematica can know it is irrational. Something like the following doesn't work. g[x_Rational | x_Integer] := x g[x_Real] := 1/x g[2] 2 But g[2.0] 0.5 does not treat 2.0 as rational. Maybe you will get a better answer on this part. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: lorenzo.keegan at handbag.com [mailto:lorenzo.keegan at handbag.com] To: mathgroup at smc.vnet.net Hello, Can you help me? How do write expressions in Mathematica for functions and sequences such as the following: f(x) = {1/x, x is irrational {x^2, x rational and f(n) = 1/n, n odd n^2, n even I am a new user and find the manual rather daunting. Best wishes Laurence Keegan