You are on page 1of 3

Matlab Exam 2 Review

http://ef.engr.utk.edu/ef230-2011-08/modules/matlab-exam2-review/

1.

Exam 2 Overview The exam will structured as a combination of multiple choice and short answer questions. The questions will attempt to assess your ability to understand and utilize the commands and methods we've covered so far this semester. It will focus primarily on the material covered since the last exam, but it will assume that you understand the basics which were covered on the first exam. You will be allowed to refer to notes, on-line materials, and Matlab itself. You will not be able to copy/paste code from the exam. You will not be successful on the exam if you expect to be able to look up and try out everything as you take the exam. It is expected that you have a basic level of familiarity with the material, and that you only need to look up details for some of the topics. A good method of preparing for the exam might be to outline what topics and commands were covered, which labs and examples covered these topics, and perhaps make notes on some of the basic examples. For example, one topic we covered was numerical integration. You should know ahead of time that you can use either trapz or quadl to do this, what the difference between the two commands is, and have a basic idea of how to use each one.

2.

Vector Indexing and Find You may find (no pun intended) this topic to be helpful with your data analysis project. A matrix index can be either a scalar (single value) or a vector. If the index is a vector, the result will be a vector as well.

abc = [2 4 6 8 10]; ii=1; abc(ii) % first element of abc is 2 ii = [3 5]; abc(ii) % 3rd and 5th elements are 6 and 10
The find command finds indexes of nonzero elements in a matrix. It is often used with a relational operator to find all elements in a matrix that meet a certain criteria.

nums = [4 18 91 42 9]; i = find(nums>40) % get the indexes where nums>40, i.e. elements 3 and 4 n40 = nums(i) % uses vector indexing to pull the values out of nums at abc = [10 11 12 13 14 15]; % a simple 2D matrix j = find(abc>12) % get the indexes where abc>12, uses linear indexing, j= [r c] = find(abc>13) % get the subscripts where abc>13, r = [2;2] and c = [
The find command is very powerful once you understand it.

scores = [100 70 80 90]; % a simple list of scores i90 = find(scores>=90) % indexes of all values >= 90 numge90 = length(i90) % determine how many are >= 90 avgge90 = mean(scores(i90)) % the average of all scores >= 90
Here is an example of looking through a list (x) to determine the number of items that exceed a given threshold (xmax). It is implemented both by a loop and by the find command.

% loop through a list of numbers (x) to count the number of items % that are above a given threshold (xmax) cnt = 0; for i=1:length(x) if x(i)>xmax cnt = cnt + 1; end

1 of 3

08/11/2011 12:47

Matlab Exam 2 Review

http://ef.engr.utk.edu/ef230-2011-08/modules/matlab-exam2-review/

end fprintf('%.0f items in x were above %.f\n',cnt,xmax); % use find to perform the same task as above i_over_list = find(x>xmax); % indices of all items in x > xmax cnt = length(i_over_list); % the number of indices is the number of items fprintf('%.0f items in x were above %.f\n',cnt,xmax);

3.

Golf Project Review Review of a golf project solution.

4.

Examples of possible short answer questions Short answer questions will require you to write and turn in short (less than 15 lines) of Matlab code. You will be able to use Matlab to create and check these answers. Example problems in the quiz format Solutions to these examples will not be posted because some of these questions may appear on the exam.

5.

Practice Problems You won't have problems like this on the exam, but you could be asked to create part of these solutions and you will have multiple choice questions on the various topics. 1. Use ode45 to find the solution for the differential equation below using the values k=50 and m=10 for the initial conditions of x(0)=3 and Dx(0)=0 and t from 0 to 8. Plot the results. Use interp1 to find the value of x and x' for t=4. Display these results on the graph.

2. Create a Matlab program to curve fit a third order polynomial to the data points in this file: polypts.csv. Produce the following plot and command window output. All output should be calculated values, not hardcoded numbers. (Hint: use Matlab's bar command to display the difference of the actual and fitted values.)

The polynomial equation is y = 0.567x^3 + -4.533x^2 + -13.933x + 19.605 The value of y at x=0 is 19.605
3. Use a dialog box to prompt the user for an equation f(x) and a range of x values. Plot the equation and its approximate (numerical) derivative and integral for the entered range. (hint - use the inline command to create a function from the entered string.)

2 of 3

08/11/2011 12:47

Matlab Exam 2 Review

http://ef.engr.utk.edu/ef230-2011-08/modules/matlab-exam2-review/

4. Calculate the definite integral of y=sin(x) from 0 to pi using the following methods Trapezoidal numerical integration (10 intervals) (Answer = 1.9797) Adaptive Simpson quadrature numerical integration (quadl) (Answer = 2.0000) 5. Read an image from a URL, scale it to a width of 100 pixels, and display it similar to what is shown below. You should use a loop and appropriate equations to place the 12 images.

File(s): exam2_review.m

3 of 3

08/11/2011 12:47

You might also like