【正文】
kPa/mol K)。 g 39。 M a r k e r S i z e 39。 ) 。 Su bp lo t 1 title 39。y 2 = exp ( x ) 。 , 39。 ) 。 title ( 39。 i nt 2 str ( i nd ex ) ] ) 。 ) 。The value is even.39。)。 else if grade disp (39。The grade is D.39。)。 elseif (b^2 4*a*c) == 0 disp (39。 value2 (d) value1 amp。 1 1 0 0 1 1 Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 14 ?Scalar value with array ?Array with array 0b?1021a??? ?????ab?10an s01??? ????1021a??? ?????0221b??? ??????ab??10a ns11??? ????Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 15 1. Both array must have the same size (or shape)。A39。 l2 l1 | l2 xor (l1, l2) ~ l1 0 0 0 0 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 22 MATLAB treats an operand as true if it is any nonzero value, and false if it is zero. ~5 is 0 ?Scalar with array Array with array 1001a??? ????0b? 00amp。 ?try/catch Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 28 The if Construct if c o n tr o l _ e x p r _ 1S ta te m e n t 1S ta te m e n t 2 B l o c k 1e l se if c o n tr o l _ e x p r _ 2S ta te m e n t 1S ta te m e n t 2 B l o c k 2e l seS ta te m e n t 1S ta te m e n t 2 B l o c k 3e n d???????????????Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 29 There can be any number of elseif clause in an if construct, but there can be at most one else clause. Note that the MATLAB keyword end in this construct is different from the function end. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 30 Quadratic equation ?If , 2 distinct real roots. ?If , single root. ?If , 2 plex roots 2 0a x b x c? ? ?2 42b b a cxa? ? ??2 40b ac??2 40b ac??2 40b ac??Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 31 if (b^2 4*a*c) 0 Write msg that equation has two plex roots. elseif (b^2 4*a*c) == 0 Write msg that equation has two identical real roots. else Write msg that equation has two distinct real roots. end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 32 if (b^2 4*a*c) 0 disp (39。)。The grade is C.39。 end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 45 (b) if grade disp (39。)。The value is odd.39。 end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 52 The try/catch Construct Special form branching construct designed to trap error. tr yS ta te m e nt 1 S ta te m e nt 2 T r y B l oc kc a tc hS ta te m e nt 1 S ta te m e nt 2 Ca tc h B l oc ke nd??????????Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 53 % I ni t i al i ze a r r aya = [ 1 3 2 5 ] 。 num 2 str ( a ( i nd ex ) ) ] ) 。 garbage 1 2 3 garbage (?1‘, ?2‘, ?3‘) Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 59 Only functions with character arguments can be treated as mands. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 60 x = 2 * pi : pi / 20 : 2 * pi 。y 2 = cos ( x ) 。hold off 。y 1 = exp ( x ) 。y = s in ( x ) 。plot ( x , y ) 。 , 39。 , 39。 r : an array of distances. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 82 Example — Cardioid Microphone The gain of such a microphone varies as a function of angle according to the equation. g : a constant associated with microphone. θ: the angle from the axis of the microphone to the sound source. 2 (1 c o s )G a in g ???Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 83 Example —Electrical Engineering : Frequency Response of a LowPass Filter RVi CVoChapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 84 R = 16kΩ C = 1μF 112oiVV j fR C?? ?Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 85 Example — Thermodynamics: The Ideal Gas Law P : the pressure of the gas in kilopascals (kPa)。 ?Additional information about plots。 \pi π \Pi Π \circ 176。 , 39。p l o t ( x , y , 39。x = pi : pi / 20 : pi 。s ub pl ot ( 2 , 1 , 1 ) 。Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 65 Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 66 Creating Multiple Figures MATLAB can create multiple Figure Window, with different data displayed in each window. Each Figure Window is identified by a figure number, which is a small positive integer. figure (n) : selects current figure. gcf : returns the number of the current figure. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 67 Example figur e ( 1 ) 。 k 39。 g r i d o nExample Chapter 3 Branching Statements and Program Design 10/23/20