CS368 Homework 2
| ||
AnnouncementsCheck here periodically.
| ||
ProblemsTo get started, download this MATLAB script: Save the script (e.g., in a MATLAB/homework2 folder - if you don't have a homework2 folder, you can create one when you save the file). Launch MATLAB and open the homework2.m script. The file is a text-only file that opens in the Editor window in MATLAB. Edit your homework2.m file with your name and answers to the problems. The header and some of the format is given to you in this template to ensure that your published results meet our expectations for this homeworks. Please do not reformat until you understand how your script headers and overall format affect the published results. Problem 1: (4 points): Creating a tip tableFor this problem you will be creating a "tip table" that could be used to look up an amount to leave as a tip given the restaurant bill. In addition to the column for the bill, the table will contain columns for 15%, 18%, and 20% tips. Create and display a matrix with four columns:
If you've constructed your matrix correctly, when it is displayed, the first few lines will look like: 5.00 0.75 0.90 1.00 10.00 1.50 1.80 2.00 15.00 2.25 2.70 3.00 20.00 3.00 3.60 4.00 To receive full credit, you must make use of MATLAB's matrix and vector creation and manipulation abilities, e.g., you cannot enter the first column in element by element, columns 2 through 4 should be calculated using column 1 (i.e., if you decided to modify the tip table to go from bill totals of $2 to $50 in increments of $3, exactly one line of the code you wrote would need to be changed). Problem 2: (5 points) Density of freshwaterThe density of freshwater can be computed as a function of temperature using the following equation: ρ = 5.5289×10-8 TC3 - 8.5016×10-6 TC2 + 6.5622×10-5 TC + 0.99987 where ρ = density (g/cm3) and TC = temperature (°C).
Problem 3: (8 points) Distance to horizonThe distance to the horizon from a location on a hill depends on both the height of the location on the hill and the radius of the planet and is given by the formula: ![]() where d = the distance to the horizon, r = the radius of the planet, and h = the height of the hill (all in the same unit of measurement). Plot the distance to the horizon vs the height of a hill for hill heights from 0 to 10,000 feet on Earth and Mars on one plot figure. Note: the diameter of the Earth is 7926 miles and the diameter of Mars is 4217 miles. To receive full credit:
Style and Technique (3 points)Part of your score on this (and, really, every) assignment is based on your style and technique. Included in this are the following:
| ||
Handing in
| ||
Last Updated: 2/9/2016 © 2016 Beck Hasti, hasti@cs.wisc.edu |