class9 - PHYS 5900 Class 9 (9/14/2009) Zi-Wei Lin Special...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
PHYS 5900 Class 9 (9/14/2009) Zi-Wei Lin Special input forms for functions: Normal form: func[arg] Postfix form: arg // func Prefix form: func@arg In[1]:= N @ Sin @ 50 Degree DD == Sin @ 50 Degree Dêê N Out[1]= True In[2]:= N @ Sin @ 50 Degree DD == N @ H Sin @ 50 Degree DL Out[2]= True In[3]:= N @ Sin @ 50 Degree DD == N @ Sin @ 50 Degree D Out[3]= True In[4]:= Sqrt @ 3.2 D Out[4]= 1.78885 In[5]:= Sqrt @ 3.2 Out[5]= 1.78885 In[6]:= 3.2 êê Sqrt Out[6]= 1.78885 Get information about user-defined functions: In[7]:= f @ x_ D : = x^3 In[8]:= ?f Global`f f @ x_ D : = x 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
We can specify usage messages for this user-defined function: In[9]:= f:: usage = "f @ x D returns the cube of x." Out[9]= f @ x D returns the cube of x. In[10]:= ?f f @ x D returns the cube of x. In[11]:= ?? f f @ x D returns the cube of x. f @ x_ D : = x 3 In[12]:= f @ y D Out[12]= y 3 In[13]:= Clear @ f D In[14]:= f @ y D Out[14]= f @ y D In[15]:= ?? f f @ x D returns the cube of x. After Clear [f], the function definition is gone, but usage message remains. In[16]:= Remove @ f D In[17]:= ?? f Information::notfound : Symbol f not found. à In[18]:= f @ y D Out[18]= f @ y D 2 class9.nb
Background image of page 2
With Remove [f], both the function definition and the usage message are gone. Relational Operators Relational operators compare lhs and rhs and return True or False whenever possible. Relational operators include lhs == rhs Equal[lhs, rhs] lhs != rhs Unequal[lhs, rhs] lhs > rhs Greater[lhs, rhs] lhs >= rhs GreaterEqual[lhs, rhs] lhs < rhs Less[lhs, rhs] lhs <= rhs LessEqual[lhs, rhs] In[19]:= f @ x_ D : = x^2 In[20]:= g @ x_ D : = x^3 In[21]:= g @ 2 D > f @ 3 D + 1 Out[21]= False In[22]:= g @ 2 D <= f @ 3 D + 1 Out[22]= True In[23]:= 8 5 == 3 == 6 ê 2 Out[23]= True In[24]:= 4 > 3 <= 2 Out[24]= False Mathematica returns the expression if they can not be compared: In[25]:= 1 + x > 2 y Out[25]= 1 + x > 2y In[26]:= Clear @ f, g D class9.nb 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Logical Operators include: expr1 && expr2 && . .. And[expr1, expr2, . ..] expr1 || expr2 || . .. Or[expr1, expr2, . ..] Xor[expr1, expr2, . ..] ! expr Not[expr] In[27]:= ?&& e 1 && e 2 && is the logical AND function. It evaluates its arguments in order, giving False immediately if any of them are False, and True if they are all True. à && stops at the 1 st expression that is false In[28]:= ?Or e 1 »» e 2 »» is the logical OR function. It evaluates its arguments in order, giving True immediately if any of them are True, and False if they are all False.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

class9 - PHYS 5900 Class 9 (9/14/2009) Zi-Wei Lin Special...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online