Matlab codes quick questions
Draw the flow diagrams for for loop and while loop, separately. (10 points)
What does a jump statement do to an iteration statement? What is the difference between a break statement and a continue statement? (10 points)
The Taylor series for the exponential function ex is given below. Write a script file using the proper iteration statement to read in a number x and calculate its exponential using Taylor series for the first 10 terms. (10 points)
1 + β (π₯^π
π! )
β
π=1
Write a script program using a proper loop statement to perform the following tasks: (20 points)
(1) Per-determine a random integer (rand_int) between [0-9] by the program (hint: use randi() ).
(2) Let the user guess a number (number) entered from the keyboard to be compared with the random integer (rand_int).
(3) If the value of number matches the value of rand_int, the program should display a message βBingo! The guessing is stopped by the program.β and terminate.
(4) If the two values of number and rand_int are not matched, the program should ask whether the user wants to keep guessing by displaying βWrong guessing… try again?β.
(5) To continue guessing, a character βYβ or βyβ should be entered from the keyboard; to stop guessing, a character βNβ or βnβ should be entered, and display βThe guessing is stopped by the user.β.
(Carefully examine through our in-class examples and exercises. Understand which loop should be used, which condition should be used for logical evaluation, and what the order of different commands should be within the loop. When you see specific keywords, e.g. keep, stop, terminate, continue, etc., know what iteration statement with jump statements should be used. Try making modifications to in-class demos to construct the program.)