Matlab tutorial course

Slides:



Advertisements
Similar presentations
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Advertisements

Matlab tutorial course Exercises 4:. Exercises – for loops Download the scripts loops_example.m and if_else_example.m, run the code Download the function,
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 12 – Craps Game Application: Introducing Random.
Lecture 15 Practice & exploration Subfunctions: Functions within functions “Guessing Game”: A hands-on exercise in evolutionary design © 2007 Daniel Valentine.
Matlab tutorial course Exercises 1:. Exercises Go back to my webpage, download the file ‘startup.m’ and save it in your MATLAB home folder – Must be directly.
Matlab tutorial course Exercises 2:. Exercises Copy the script ‘face_points.m’ from my webpage into your ‘scripts’ folder Create a new folder in your.
THE BIG PICTURE. How does JavaScript interact with the browser?
MOM! Phineas and Ferb are … Aims:
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
DiceRoller DiceRoller (object class) and DiceRollerViewer client class: Write a DiceRoller class (similar to Yahtzee) to: Allow the person to initially.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
 There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there.
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Chapter 6 Methods: A Deeper Look. Objectives In this chapter you will learn: How static methods and fields are associated with an entire class rather.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 13 Conditional.
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
C++ LANGUAGE TUTORIAL LESSON 1 –WRITING YOUR FIRST PROGRAM.
Cumulative algorithms. 2 Adding many numbers How would you find the sum of all integers from ? // This may require a lot of typing int sum = 1 +
 2000 Prentice Hall, Inc. All rights reserved. 5.2Program Modules in C Functions –Modules in C –Programs combine user-defined functions with library functions.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 13 Conditional.
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
AP Java Java’s version of Repeat until.
1 BUILDING JAVA PROGRAMS CHAPTER 5 PROGRAM LOGIC AND INDEFINITE LOOPS.
Objective of the lesson Use Blockly to make a dice for Snakes and Ladders All of you will: – Make an image which displays when you press a button Most.
This is a while loop. The code is done while the condition is true. The code that is done is enclosed in { }. Note that this program has three parts: Housekeeping.
Section 5.5 Application: The Card Game of War. 5.5 Application: The Card Game of War A deck of cards is shuffled and dealt to two players The players.
DEVRY CIS 336 W EEK 7 G ROUP P ROJECT T ASK 5 Check this A+ tutorial guideline at
Modelling and Simulating Social Systems with MATLAB
Recap: If, elif, else If <True condition>:
Repetition Structures
Modelling and Simulating Social Systems with MATLAB
Diamond Hunt Mock Programming Project.
Engineering Innovation Center
Introducing Do While & Do Until Loops & Repetition Statements
BBC Microbit.
Control Statement Examples
Writing Functions( ) (Part 5)
Class Constructor Recall: we can give default values to instance variables of a class The “numberOfPlayers” variable from the “PlayerData” class before.
Building Java Programs
The while Looping Structure
A TOUR of WileyPLUS.
Truth tables: Ways to organize results of Boolean expressions.
Matlab tutorial course
Matlab tutorial course
For Loops.
Repetition Structures
Remembering lists of values lists
Truth tables: Ways to organize results of Boolean expressions.
DICES ROLLING Sample This is an example text. Go ahead an replace it with your own text. This is an example text.
int [] scores = new int [10];
Matlab tutorial course
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Computer Science I: Get out your notes.
Basic Mr. Husch.
Chapter 13 Conditional Repetition
The while Looping Structure
How to allow the program to know when to stop a loop.
GCSE Computing.
GCSE Computing.
Presentation transcript:

Matlab tutorial course Exercises 4:

Exercises – for loops Download the scripts loops_example.m and if_else_example.m, run the code Download the function, roll_a_dice.m, this simulates rolling a dice to return an integer between 1 and 6 Write a function to show the result of rolling a dice 5 times. When your functions runs it should produce a result like: Roll 1, you scored 3 Roll 2, you scored 1 etc… Change the function so it has an input that specifies the number of rolls Hint: use the examples in the scripts to help you. Bart may also provide some assistance!

Exercises – while loops Now write a function using a while loop, to simulate rolling a dice until you score a 6. The output of your function should look something like: Roll 1, you scored 5 Roll 2, you scored 6 Modify the function so it counts the number of rolls it took to win Add code to tell the player they have won Congratulations, you won after 2 rolls!! Return the number of rolls as output to the function

Exercises – while loops and if/else Now write a new function, that specifies a maximum number of rolls as input. If the players scores a 6 they win as before. However, if after the n-th roll they still haven’t rolled a 6, then they lose The final display of your output should either be Congratulations, you won after 2 rolls!! Or I'm sorry, you used up 5 rolls without scoring a 6. You lose!! Hint you will need to use if/else statements When you have finished, download all the rolling dice functions, these provide my sample answers and will be useful for you to keep