RE: Drawing intrinsic coordina
- To: mathgroup@smc.vnet.net
- Subject: [mg11068] RE: [mg10978] Drawing intrinsic coordina
- From: Ersek_Ted%PAX1A@mr.nawcad.navy.mil
- Date: Wed, 18 Feb 1998 20:32:20 -0500
Adrian wrote: ---------- |Anyone know how (possibly with an add-in package?) to draw intrinsic |coordinate graphs with Mathematica 3? Also, anyone know how to |implement a RationalQ function that tells if the supplied parameter is |rational or not, e.g. | | RationalQ[Sqrt[2]] = False | RationalQ[1/3] = True | Don't know what you mean about an intrinsic coordinate graph. But I can answer your problem with RationalQ. There are several ways to do it. It all depends what you want. First approach: In[1]:= RationalQ1[_Rational]:=True RationalQ1[_]:=False In[3]:= Clear[x]; {RationalQ1[Sqrt[2]], RationalQ1[1/3], RationalQ1[Sqrt[3] x+Sqrt[3](Sqrt[3]/2-x)]} Out[3]= {False,True,False} Now is that right? Sqrt[3] x+Sqrt[3](Sqrt[3]/2-x) simplifies to (3/2) but Out[3] above says it isn't rational. To fix that you can use the next approach: If you really want to cover your bases you can use FullSimplify instead of Simplify, but it sometimes takes a very long time. In[5]:= RationalQ2[x_]/;(Head@Simplify@x===Rational):=True RationalQ2[x_]/;(Head@Simplify@x=!=Rational):=False In[7]:= {RationalQ2[Sqrt[2]], RationalQ2[1/3], RationalQ2[Sqrt[3] x+Sqrt[3](Sqrt[3]/2-x)], RationalQ2[x]} Out[7]= {False,True,True,False} Now we see (Sqrt[3] x+Sqrt[3](Sqrt[3]/2-x)) is considered rational. Except I cleared (x) above, and Out[7] above says (x) is not rational. What if you want to say (x) may represent a number, and that number may be rational. The next approach fixes that. In[8]:= RationalQ3[x_]/;(Head@Simplify@x===Rational):=True RationalQ3[x_]:=With[{temp=Simplify[x]}, False/;(Head[temp]=!=Rational&&NumericQ[temp])] In[10]:= {RationalQ3[Sqrt[2]], RationalQ3[1/3], RationalQ3[Sqrt[3] x+Sqrt[3](Sqrt[3]/2-x)], RationalQ3[x]} Out[10]= {False,True,True,RationalQ3[x]} Now RationalQ3[x] doesn't change during evaluation. We still find that (Sqrt[3] x+Sqrt[3](Sqrt[3]/2-x)) is considered Rational. Ted Ersek