Difference between revisions of "EGR 103/Fall 2017/Lab 4"
(No difference)
|
Revision as of 16:57, 17 September 2017
Typographical errors
None identified yet!
4.1 Introduction
The main purpose of this lab is to learn how to write functions and to use selective structures. The following is a companion piece to the lab handout itself. The sections in this guide will match those in the handout.
4.2 Resources
See main EGR 103 page for links to these
4.3 Getting Started
Same as it ever was.
4.4 Ungraded
These problems are good ones to look at and to solve but are not a part of the graded work. Given that, you can absolutely consult with classmates about how to get the answers to these ungraded problems.
4.5 Assignment
4.5.1 Chapra 2.10
See the MATLAB:Plotting page for information about the additional pieces of information you can give the plot
command to change sizes and colors.
4.5.2 Chapra 2.27
Pretty straightforward. Note that your function will only have three lines of code - the paradigm (the first line at the top of the function that defines the file as a function and names the outputs and inputs) and the two lines that calculate x and y, respectively. The script should to the rest. Putting too much in the function is grounds for losing points. Precious, precious points.
4.5.3 Palm 3.12
See MATLAB:Selective Structures for a reminder of how to use an if
tree. Also, think about the order in which you should check for valid arguments. A good first thing to check is whether the user even gave you two arguments to begin with!
4.5.4 Pick a card!
Make sure you understand how mod
works and the result it is giving you for mod(CardNum, 13)
before attempting to modify it to produce the result you want. If you want to know more about the for
loop, you can look at MATLAB:Iterative Structures. Also, if you want to know more about how BuildTester
works, you can type help BuildTester
. Note that a .p
file is a pre-compiled MATLAB file; it will run but you can't look at the code.
4.5.5 What card is that?
Make sure your function produces two different outputs for this one. If you want to know more about how InfoTester
works, you can type help InfoTester
.
4.5.6 Is that a three of a kind‽
Before tackling this one, really think about what you the human would do to see if a person has three of a kind -- what information is important and what information is irrelevant.
If you want to know more about how TOKTester
works, you can type help TOKTester
.
General Concepts
This section is not in the lab report but rather has some items in it that span multiple problems in the lab.
Functions
See Chapra 3.1.2 and Palm 3.2 through page 123
Selective Structures
See MATLAB:Selective Structures, and note especially that if trees will only run if all the logical expression it is given is true. If you want to run when any of them is true, put the any() command with it. Also see Chapra 3.3.1 and Palm 4.4