Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox.

Similar presentations


Presentation on theme: "Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox."— Presentation transcript:

1 Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox

2 You are going to See that MuPAD provides flow control mechanism, such as if and loops Get to know how to use if and case statements Use for, while, repeat statements to iterate various loops 2

3 type and testtype Useful for checking some conditions 3 Cf. domtype() For all available Types

4 IF statement if condition 4 if condition – else x<0 S1 x<0 S1 T F S2 T F S1 S2

5 Multiple Conditions Logical Operations 5 and or not xor ==>

6 F F if – elif – else – end_if F Nested IF 6 if S1 S2 T elif S3 S4 T T S1 S2 S3 S4

7 Case Statement 7 Define a new procedure.

8 Return Value Result of the last executed command 8 Abs is a function. One of them becomes the return value. One of them becomes the return value.

9 Displaying Intermediate Results No automatic display inside conditional statements. Use print to display something. 9

10 Exercise In if statements the system evaluates composite conditions with Boolean operators one after the other. The evaluation routine stops prematurely if it can decide whether the final result is TRUE or FALSE (“lazy evaluation”). Are there problems with the following statements? What happens when the conditions are evaluated? 10

11 For Loops : Fixed No. of Iterations for loop with step 11

12 For Loops Down to Lists, Matrices 12

13 While and Repeat while Repeat 13

14 Nested Loops Loop in a Loop 14

15 Exiting a Loop break – exit from the nearest loop 15 Empty List List Concatenation

16 Exercise Write the expected output from the previous commands without using MuPAD. 16

17 Skipping Part of Iteration next 17 Skip this. Go to the end of the loop. Skip this. Go to the end of the loop.

18 Return Value of a Loop The result of the last executed statement Use a colon to suppress displaying the return value. 18

19 Key Takeaways Now, you are able to control a conditional execution of a set of statements using if and case, use for loop to repeat some actions for a fixed number of times, check loop exit condition using while and repeat – until statements, and to control looping actions using next and break statements. 19

20 Notes 20


Download ppt "Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox."

Similar presentations


Ads by Google