{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# class21 - PHYS 5900 Class 21 Fri Zi-Wei Lin Test 2 will be...

This preview shows pages 1–4. Sign up to view the full content.

PHYS 5900 Class 21 (10/16/2009 Fri) Zi-Wei Lin Test 2 will be on Nov 6 (F) 11:00am-1:30pm. There will be no classes on Nov 2 (M) & 4 (W); instead, the four classes on Oct 19, 21, 26 & 28 will be extended by 25 minutes each, i.e., they will go from 11:00am to 12:15pm. Defaults x_:v represents any single expression to be named x on the right-hand-side, x has a default value of v if x is omitted. patt:v = Optional[patt,v] In[1]:= ? : System` Optional Pattern In[2]:= ? Optional p : v is a pattern object which represents an expression of the form p , which, if omitted, should be replaced by v . ± In[3]:= 8 a, b < ± . 8 x_, y_ < : > 8 x^2, y^2 < Out[3]= 9 a 2 , b 2 = In[4]:= 8 a, b < ± . 8 x_, y_: d < : > 8 x^2, y^2 < Out[4]= 9 a 2 , b 2 = In[5]:= 8 a < ± . 8 x_, y_: d < : > 8 x^2, y^2 < Out[5]= 9 a 2 , d 2 = In the above, y is given the default value of d when y is omitted. In[6]:= 8 a, 2 < ± . 8 x_, y_Integer: 10 < : > 8 x^2, y^2 < Out[6]= 9 a 2 , 4 = In[7]:= 8 a < ± . 8 x_, y_Integer: 10 < : > 8 x^2, y^2 < Out[7]= 9 a 2 , 100 =

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

View Full Document
The following cases do not match the pattern : In[8]:= 8 a, 2, 3 < ± . 8 x_, y_Integer: 10 < : > 8 x^2, y^2 < Out[8]= 8 a, 2, 3 < In[9]:= 8 a, b < ± . 8 x_, y_Integer: 10 < : > 8 x^2, y^2 < Out[9]= 8 a, b < In[10]:= 8 a, 2. < ± . 8 x_, y_Integer: 10 < : > 8 x^2, y^2 < Out[10]= 8 a, 2. < x_. represents an expression with a built-in default value x_+y_. default for y is 0; x_*y_. default for y is 1; x_^y_. default for y is 1. In[11]:= a + b ± . x_ + y_. : > x^2 + y^2 Out[11]= a 2 + b 2 In[12]:= a ± . x_ + y_. : > x^2 + y^2 Out[12]= a 2 In[13]:= a * b ± . x_ * y_. : > x^2 + y^2 Out[13]= a 2 + b 2 In[14]:= a ± . x_ * y_. : > x^2 + y^2 Out[14]= 1 + a 2 In[15]:= a ± . x_ ^y_. : > x^2 + y^2 Out[15]= 1 + a 2 Example3.2.1 Contruct a pattern to represent the difference of any two single expressions. In[16]:= MatchQ @ a - b, x_ - y_ D Out[16]= True In[17]:= MatchQ @ a - 2 * b, x_ - y_ D Out[17]= False 2 class21.nb
In[18]:= MatchQ @ a - 5, x_ - y_ D Out[18]= False In[19]:= FullForm @ x_ - y_ D Out[19]//FullForm= Plus @ Pattern @ x, Blank @DD , Times @ - 1, Pattern @ y, Blank @DDDD In[20]:= FullForm @ a - 5 D Out[20]//FullForm= Plus @ - 5, a D In[21]:= FullForm @ a - 2 * b D Out[21]//FullForm= Plus @ a, Times @ - 2, b DD In the above, -5 is an Atom, so it does not have the structure of Times[-1, . ..] . The negative term in the difference of any two expressions involves the following 2 cases:

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

class21 - PHYS 5900 Class 21 Fri Zi-Wei Lin Test 2 will be...

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

View Full Document
Ask a homework question - tutors are online