CS 104 - Lab 2 Due in Blackboard Assignment (one file named lastnameLab2.txt) by
ID: 3649054 • Letter: C
Question
CS 104 - Lab 2Due in Blackboard Assignment (one file named lastnameLab2.txt) by Friday 9/14 midnight
Objectives:
(5 points) Answer some basic questions about Matlab 1. and the development environment.
2. (15 points) Solve some basic, scalar calculator problems in Matlab.
Pre-Read/Pre-View:
Getting Started with Matlab http://www.mathworks.com/demos/matlab/getting-started-with-matlabvideo-
tutorial.html (headphones needed in lab)
Working in the Development Environment http://www.mathworks.com/demos/matlab/working-in-thedevelopment-
environment-matlab-video-tutorial.html (headphones needed in lab)
Writing a Matlab Program http://www.mathworks.com/demos/matlab/writing-a-matlab-programmatlab-
video-tutorial.html (headphones needed in lab)
Chapter 1: Tutorial lessons 1 of http://www.mccormick.northwestern.edu/docs/efirst/matlab.pdf
1.Vectors, 2.Matrices, 3.Vector operations http://www.cyclismo.org/tutorial/matlab/
Matlab formatting reference (we will use sprintf, but formatting is the same as fprintf)
http://www.craigschiller.com/portfolio/fprintf/fprintf.pdf
optional MATLAB for Engineers - Chapter 2 (skip Array Operations pages 27-37), Chapter 3.1-3.4,
3.8, 7.1
Tasks:
1. (5 points) Answer some basic questions about Matlab and the development environment.
A. When using Matlab like a calculator, where do you enter variables, assign values to variables and
expressions?
B. What characters do you use to designate the value for a vector (or array) variable, instead of a scalar
variable?
C. What is the Command History window used for?
D. What character do you end a command with to supress output?
E. Where can you look up all the current values of variables?
F. What happens when you evaluate an arithmetic expression containing a vector variable instead of a
scalar variable?
G. How can you browse available Matlab functions?
H. What are the arguments for a function?
I. When looking in the Workspace Browser, how do you know which variable is a scalar, which is a
vector, and which is a matrix?
J. Where does the result get stored of an arithmetic expression that you do not assign to a variable?
K. At what value do array indices start at in Matlab?
IIT - CS104 Lab 2 http://www.cs.iit.edu/~cs104/labs/Lab2/Lab2.html
1 of 3 8/12/2012 1:39 PM
2. (15 points) Solve some basic, scalar calculator problems in Matlab.
For each problem complete the following steps:
Draw a picture or write pseudocode for solving 1. the problem using composition.
2. By hand, make an estimate of roughly the scale of the answer and complete the Test Case table.
Write Matlab "calculator" code to solve the following problems, save all your work in a
command history file. It is fine to include errors in your command history file, as long as you
eventually compute correctly. If you discover mistakes in your program, correct them and
execute the test plan again. Please try to format the results to significant digits that are correct for
the problem and data given.
See http://en.wikipedia.org/wiki/Significant_figures
3.
How to create a command history file??
>> diary BauerLab2.txt
. . .
>> diary off
Problems:
A. The bank wants to be sure you can afford to pay them back before they give you a mortgage. One
way they consider your ability to repay is by making sure your total debt doesn't exceed a certain
percentage of your income, usually 36-42%. This percentage is called the debt ratio. Given your
income (a real number) and other monthly debt (a real number), you can use the following formulas to
determine the lower and upper limits on your monthly mortgage payments.
Lower limit = (36% of your income) minus your other monthly debt
Upper limit = (42% of your income) minus your other monthly debt
Test Case Sample Data Expected Result
(manually calculate) Verified?
High Debt income: 4000
monthly debt:1000
Lower Limit: $440.0
High Limit: $680.0
Low Debt income: 6000
monthly debt: 500
No Debt income: 3000
monthly debt: 0
Make up an example
B. The CSxxx course has the following weighting for the various course assessments:
Quiz #1 10%
Quiz #2 15%
Midterm 25%
Final exam 30%
IIT - CS104 Lab 2 http://www.cs.iit.edu/~cs104/labs/Lab2/Lab2.html
2 of 3 8/12/2012 1:39 PM
Lab grades 20%
TOTAL 100%
The grading TA would like a program to calculate a student's weighted final numeric grade. Typically
the TA would like to enter the assignment grades as integers but would like the final grade to be in
decimal. Given the assignment grades, calculate the weighted final numeric grade using the weights
shown.
Test Case Sample Data Expected Result
(manually calculate) Verified?
poor student 0 45 64 65 70 final numeric grade = 56.25
good student 90 80 85 84 95
fair student 70 80 72 77 84
your grades?
C. In an updated version of the popular 80's videogame Ms. Pacman, they have added a second way to
score your play and compare players' abilities, the power rating. A player's power rating is calculated as
follows: power rating = (10*fruits eaten + 5*ghosts eaten) divided by (time playing the game in
seconds)
Test Case Sample Data
Expected
Result
(manually
calculate)
Verified?
Bob Smith Fruits:3 Ghosts:9
Time:258
Power rating:
.291
Mary Smith Fruits:8 Ghosts:19 Time:358 Power rating:
.489
Smitty Smith Fruits:2 Ghosts:47 Time:189 Power rating:
Your Name Fruits: Ghosts:
Time: Power rating:
D. Write a MATLAB statement to simulate a random 6-sided die. How do you think you would test
your code to verify it is working correctly?
E. Create a test table and write an m-file script to solve the following problem. An object is thrown
vertically from the ground with initial speed v0=35 m/sec. Assume that acceleration due to gravity is
-10m/sec^2 and neglect air friction.
Compute and display the total flying time of the object
Compute and display the maximum height of the object
Copyright CS, Illinois Institute of Technology
IIT - CS104 Lab 2 http://www.cs.iit.edu/~cs104/labs/Lab2/Lab2.html
3 of 3 8/12/2012 1:39 PM
Explanation / Answer
One question per post is allowed.