CISC 130 - Problem Solving in the Natural Sciences - Exam 2 Make-Up
Closed Book - Closed Notes - Calculators Permitted
65 Minutes - 100 Points
NAME______NAME
DIRECTIONS: Answer all questions on this exam in the space provided. Show all work necessary in arriving at any result.
1. (11 pts.) Write MATLAB code to generate / return / yield / give the even indexed elements of a vector named v.
2. (16 pts.) Write MATLAB code to generate / compute the Fibonacci numbers starting ;with 0 and 1. [Each number in a Fibonacci sequence is the sum of the previous 2. In mathematical notation:
] Generate the first 500 numbers in the sequence.
3. (10 pts.) For each of the filetypes listed below fill in the most likely file extension for MATLAB running on a PC with a Windows XP operating system. The first four file extensions have already been filled in for you.
Extension / Filetype.html / WWW files in the hypertext markup language
.mp3 / A compressed format for storing music
.jpg / A compressed format for storing photographs
______/ Rich Text Format: a word processing format used to exchange data between word processors
______/ Spreadsheet files from Microsoft Excel
______/ Comma Separated Values: a spreadsheet and database format used to exchange columnar data
______/ Document files from Microsoft Word through Word 97
______/ Portable Document Format: a platform-independent format from Adobe that preserves formatting
______/ A text file containing MATLAB commands
______/ A binary file containing MATLAB variables and their values
______/ A text file containing numerical or character data in ASCII
4. (11 pts.) Write a MATLAB script file (NOT a function file) containing code to swap 2 numbers stored in variables named a and b.
Code in the script file:Code in Matlab to set up and then use the script file:
|
|
|
|
|
|
|
|
|
|
|
|
|
5. (11 pts.) Write a MATLAB function file containing a function named mymin. The code your write for mymin(a, b) [a and b are interpreted as numbers] is to return the smaller of the two parameters (i.e. the lesser of a and b). You may not use any MATLAB built-in functions.
Code in the function file:Code in Matlab to set up and then call the function:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6. (16 pts.) Write a MATLAB function file containing a function named myvmin. The code you write for myvmin(v) [v is interpreted to be a vector] is to return the smallest value in the vector. You may not use any MATLAB built-in functions.
Code in the function file:Code in Matlab to set up and then call the function:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7. (2 pts.) Describe the syntax used to write comments in MATLAB.
8 (16 pts.) Write a MATLAB function tot (v, len) that returns the total of the first len elements in the vector v. You may not use any MATLAB built-in functions.
Code in the function file:Code in Matlab to set up and then call the function:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9. (7 pts.) Describe a mechanism for passing a file name or a command name into a MATLAB function for use (for example reading the file, executing the command) by the function. [MATLAB code is optional.]
CISC 1301Exam 2, Fall, 2009