Re: Not quite a Swell FLOOP
- To: mathgroup at smc.vnet.net
- Subject: [mg37446] Re: Not quite a Swell FLOOP
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Wed, 30 Oct 2002 00:50:49 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Steven Hatton was wondering about OOP support in Mathematica. You are correct in that Mathematica doesn't have built-in support of OOP. I also don't care much for Dr. Maeder's OOP package. However, I am only a beginner with OOP, so my assessment may not be accurate. If you are going to become proficient with Mathematica you need to let go of your OOP way of doing things, and learn the Mathematica way. Mathematica actually has a beautiful and powerful language, but you need to learn how to use it. I give some useful examples below. What would be needed to do these things in another language or some other math software? ---------- Here I find all {x,y} pairs with (y>5) and return {x, y, x^2+y^2}. Notice the mixed data types. In[1]:= data={{12,2},{3,4},{2,2 Pi},{7,13.4},{3,22},{11,2},{10,9},{6,9.3}}; Cases[data,{x_,y_}/;y>5:>{x,y,Sqrt[x^2+y^2]}] Out[2]= {{2, 2*Pi, Sqrt[4 + 4*Pi^2]}, {7, 13.4, 15.1182}, {3, 22, Sqrt[493]}, {10, 9, Sqrt[181]}, {6, 9.3, 11.0675}} --------- Next I define a function that takes any numeric value. Here (z) has no numeric value so f[z] is undefined. Again notice the mixed data types. In[3]:= f[x_?NumericQ]:=x^2+1; f/@{z,3,2Pi,4.5,2+3I} Out[4]= {f[z], 10, 1 + 4*Pi^2, 21.25, -4 + 12*I} -------------- Mathematica has a rich set of functions that let you perform various useful operations. Here I take a long list and break it into a set of smaller lists. We can get many variations of this by giving Partition other arguments. In[5]:= lst={1,2 Pi,3+x,4,5,6-x,7,8x,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, 28,29,30}; Partition[lst,4,3] Out[6]= { {1, 2*Pi, 3 + x, 4}, {4, 5, 6 - x, 7}, {7, 8*x, 9, 10}, {10, 11, 12, 13},{13, 14, 15, 16}, {16, 17, 18, 19}, {19, 20, 21, 22}, {22, 23, 24, 25}, {25, 26, 27, 28} } -------------- In addition to the examples above - Mathematica has a tremendous amount of mathematical knowledge built-in. - With Mathematica doing and calculations with high precision is trivial. - With Mathematica calculations involving integers with thousands, or millions of digits is trivial. --------- Regards, Ted Ersek Download my latest Mathematica Tips, Tricks from http://www.verbeia.com/mathematica/tips/Tricks.html or from http://www.mathsource.com/Content/General/Tutorials/0212-331