freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

matlab編程第三章-在線瀏覽

2024-11-05 22:41本頁面
  

【正文】 Prompt user to enter temperature in degrees Fahrenheit Read temperature in degrees Fahrenheit (temp_f) temp_k in kelvins ← (5/9) * ( temp_f – 32 ) + Write temperature in kelvins Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 11 Relational and Logical operators Two type of operators can produce true/false result in MATLAB : relational operators and logic operators. MATLAB does not have boolean or logical data type. MATLAB interprets a zero value as false result。 any nonzero value as true result. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 12 Relational Operators a1 op a2 a1 and a2 are arithmetic expressions, variables, or strings. Operator Operation = = Equal to ~ = Not equal to Greater than = Greater than or equal to Less than = Less than or equal to Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 13 3 4 3 = 4 3 = = 4 3 4 4 = 4 39。 39。 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)。 b = sin (pi)。 Logical AND | Logical OR xor Logical Exclusive OR ~ Logical NOT Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 21 Inputs and or xor not l1 l2 l1 amp。00ab??? ????1001a??? ????1100b??? ????11|01ab??? ????Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 23 Hierarchy of operations: Logic operators are evaluated after all arithmetic operations and all relational operators have been evaluated. 1. All arithmetic operators. 2. All relational operators. 3. All ~ operators. 4. All amp。 value2 (d) value1 amp。 (value2 | value3) (f) ~(value1 amp。 ?switch。This equation has two plex roots.39。 elseif (b^2 4*a*c) == 0 disp (39。)。This equation has two distinct real roots.39。 end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 33 Good Programming Practice Always indent the body of an if construct by 2 or more spaces to improve readability of the code. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 34 Examples Using if Constructs Example — The Quadratic Equation Design and write a program to solve for the roots of a quadratic equation, regardless of type. Solution: 1. State the problem. 2. Define the inputs and outputs. 3. Design the algorithm Read the input data Calculate the roots Write out the roots 2 0a x b x c? ? ?Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 35 Prompt the user for the coefficients a, b, and c. Read a, b, and c discriminant ← b^2 4*a*c if discriminant 0 x1 ← (b + sqrt (discriminant)) / (2*a) x1 ← (b – sqrt (discriminant)) / (2*a) Write msg that equation has two distinct real roots. Write out the two roots. elseif discriminant == 0 x1 ← b / (2*a) Write msg that equation has two identical real roots. Write out the repeated roots. else real_part ← b / (2*a) imag_part ← sqrt (abs (discriminant)) / (2*a) Write msg that equation has two plex roots. Write out the two roots. end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 36 4. Turn the algorithm into MATLAB statements. 5. Test the program. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 37 Example — Evaluating a Function of Two Variables Write a MATLAB program to evaluate a function f (x, y) for any two userspecified values x and y. The function f (x, y) is defined as follows. 22220 a n d 00 a n d 0( , )0 a n d 00 a n d 0x y x yx y x yf x yx y x yx y x y? ? ??? ? ? ??? ?? ? ??? ? ? ??Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 38 Solution 1. State the problem. 2. Define the inputs and outputs. 3. Design the algorithm. Read the input values x and y Calculate f (x, y) Write out f (x, y) Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 39 Prompt the user for the values x and y Read x and y if x ≥ 0 and y ≥ 0 fun ← x + y elseif x ≥ 0 and y 0 fun ← x + y^2 elseif x 0 and y ≥ 0 fun ← x^2 + y else fun ← x^2 + y^2 end Write out f (x, y) Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 40 4. Turn the algorithm into MATLAB statements. 5. Test the program. Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 41 Notes Concerning the Use of if Constructs nest : if x 0 ... if y 0 ... end ... end Chapter 3 Branching Statements and Program Design 10/23/2022 Hangzhou Dianzi University 42 The MATLAB interpreter always associates a given end statement with the most recent if statement. Multiple elseif clause vs nested if statements Chapter 3 Branching Statements and Program Design 10/
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評公示相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1