CS100M Prelim 1 review questions ------------- Chapman 3.5,3.6,3.8,4.5,4.6,4.20 ------------- 1. Concepts: I/O, conditionals, mod Read in the year and print whether it is a leap year using (something equivalent to) the rules below: Rule 1. A non-multiple of 4 is not a leap year. Rule 2. A multiple of 4 is a leap year. Rule 3. Rule 2 does not apply to multiples of 100. Rule 4. Rule 3 does not apply to multiples of 400. Hint: REM and MOD are MATLAB functions for finding the remainder. Use HELP to check them out. E.g., rem(x,y) returns the remainder when x is divided by y. ------------- 2. Concepts: I/O, simple matrix manipulation, array arithmetic, MATLAB functions Annual US fatality rates (per 100 million vehicle miles) on all roads are stored in a file called $rates.dat$ as an n-by-3 matrix: - column 1 contains the years - column 2 contains the actual rates - column 3 contains the model predicted rates For example, a row in the file $rates.dat$ looks like this: 1978 3.39 3.31 Write a program that performs the following tasks: - read the data in the file $rates.dat$ - store the actual fatality rates as the vector variable $actual$ - store the model predicted rates as the vector variable $model$ - for each year, calculate the percent error of the modeled rate. Percent error is (|actual-model|/actual)*100 Store the percent errors in a vector variable $errors$ - Calculate the average percent error (for all years) Potentially useful MATLAB functions: INPUT, LOAD, SIZE, ABS, SUM, MEAN