MathGroup Archive 2004

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

Search the Archive

RE: functions

  • To: mathgroup at
  • Subject: [mg45507] RE: [mg45481] functions
  • From: "David Park" <djmp at>
  • Date: Sat, 10 Jan 2004 16:43:27 -0500 (EST)
  • Sender: owner-wri-mathgroup at


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.


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




does not treat 2.0 as rational. Maybe you will get a better answer on this

David Park
djmp at

From: lorenzo.keegan at [mailto:lorenzo.keegan at]
To: mathgroup at


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

      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

  • Prev by Date: Re: functions
  • Next by Date: Re: functions
  • Previous by thread: Re: functions
  • Next by thread: Re: functions