midterm1review - Midterm 1 Review These questions are...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Midterm 1 Review These questions are designed to help you think about course material, not to show you actual exam questions. The exam will be about 40-60 percent multiple choice, as discussed in class. The remainder will be short answer or coding. Research shows that the best way to study for an exam is with other people. In group study, the people who start knowing more learn more (think about why), so don’t think that it is only valuable to study with people who know more than you do. 1. (16 pts) Complete this code section with a for loop that traverses the array x and does two things: it changes any value 4 to a zero; and it adds one to any other number. Use the code framework provided and fill in the blanks. Do not change the code provided. For example, after the script the matrix shown should be [3 8 0 6]. x = [2 7 4 5]; for ___________________ if (__________________) _________________ else _________________ end end 2. (20 pts) Suppose you are given a function that calculates the area of a circle, called calcCir- cleArea. You type “help calcCircleArea” and see the following: %calcCircleArea(radius) returns the area of a circle. Write a different function that 1) asks a user for a radius, 2) calls the function calcCir- cleArea, and 3) prints a nice message that includes the area of the circle. The function should not perform arithmetic. For each of the following questions, assume you are at the start of a Matlab session (i.e. this is the first command). any script or function code is in a correctly named file in the current directory. If the code will not run correctly, choose “error”. 3. (2 pts) Consider the function f: function answer = f() answer = 7; end 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What will be in x after the command: >> x = f(); (a) 7 (b) f(7) (c) answer (d) error (e) none of these 4. (2 pts) Consider the function f: function [] = f(x) output = 7; end What will be in x after the command: >> x = f(3); (a) 7 (b) f(7) (c) ans (d) error (e) none of these 5. (2 pts) Which expression tests whether variable x is between (but not the same as) the values 5 and 10. (a) 5 < x < 10 (b) 5 <= x <= 10 (c) (d) (e) none of these 6. (2 pts) Which of the following is a MATLAB expression for testing “x is outside the range from 3 to 5” (the range includes 3 and 5)? (a) (b) 3 > x | x < 5 (c) 3 > x | x > 5 (d) cannot be expressed in MATLAB (e) none of the above 2
Background image of page 2
7. (2 pts) In MATLAB the value 1 is true, and true is: (a) there are no boolean types in MATLAB (b) any value that isn’t zero (c) 1 (d) 0 (e) none of the above 8. (2 pts) A call to zeros(2) will produce which of the following? (a) 0 0 (b) 0 0 0 0 (c) 0 0 (d) error (e) none of these 9. (2 pts) A call to ones(2) will produce which of the following? (a)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

midterm1review - Midterm 1 Review These questions are...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online