Vous êtes sur la page 1sur 8

ECOR 2606 D Winter 2018 Midterm – Version 1

Permitted Aids: Approved Calculator and Provided MATLAB Reference / Formula Sheet (last page)

Sec1(/20) Sec2(/20) Penalties Total(/40)

Last Name: ________________________________ First Name: ______________________________

Student Number: __________________________

Circle Your Lab Section:

M1600 (L5) W1420 (L7) R1000 (L4) R1130 (L3)

R1430 (L1) R1600 (L8) F1130 (L6) F1430 (L2)

This exam is 75 minutes long. There are two sections worth 40 marks on 8 pages. Attempt all questions. The last page is
your reference material. You may remove the last page from the exam. Use the backs of the pages for rough work. Do
not ask a question unless you believe that you have found a typo. Be sure that you have clearly written your name and
student number above and on the Scantron sheet as well as circled your lab section. The answers to questions 1-16
should be circled on the exam paper and entered on the Scantron. Be sure you are writing this exam in your assigned
room with your correct lecture section. Your answers on this document must be written in black or blue indelible ink.
The Scanton must be completed with an HB pencil. Marks will be deducted or other sanctions will be imposed if you
do not follow the instructions.

Penalties:

- Writing in the wrong room or writing at the wrong time -10


- Not including your name or student number on this paper or the Scantron -5
- Not indicating your lab section -5
- Not writing the exam with blue or black indelible ink – revocation of the right to have the exam reviewed.

All rights reserved: No part of this document may be reproduced, stored in a retrieval system, or transmitted in any
form or by any means, electronic, mechanical, photocopying, recording or otherwise without prior written permission
from the instructor.

1
Section 1 (questions 1-12 worth 1 mark for total of 12 marks; Questions 13-16 are each worth 2 marks for a total of 8
marks)

Question 1 through 4 reference the following mathematical functions:

𝑔 = @(𝑥) 5 ∗ exp(𝑥) / sin(2/𝑥); ℎ = @(𝑥) 3 ∗ 𝑥 . ^ 2 − 2 ∗ 𝑥;

1. What is the minimum number of dots “.” to be added to the functions to make them vector input friendly:
a. 3
b. 2
c. 1
d. 0
e. More than 3

2. The dot provided in the functions as stated above is necessary.


a. False
b. True

3. What function would you have to create to be able to find and intersection of g(x) and h(x), i.e. an x value
where g(x) = h(x)?
a. k =@(t) h(t) – g(t);
b. k =@(x) g – h;
c. k =@(x) g(x) + h(x);
d. k = g(x)– h(x);
e. a) or c)

4. Given your answer to question 3, what MATLAB library function would then be required to solve for the
intersection?
a. fzero and roots could both be used
b. neither fzero nor roots can be used
c. roots
d. fzero
e. fminbnd

2
Questions 5-7 pertain to the following False Position root finding problem.
𝑙𝑜𝑔10 (𝑥)
Complete the following tables for 𝑓(𝑥) = − 0.05 . There may be table cells that should be left blank. In that
2𝑥
case, the cell should contain “N/A”

Step XL XU XR f(xR) EA
1 1.0000 6.0000
2

5. Before you start the table, you should calculate f(1) and f(6). Why is this information important for doing the
subsequent calculations?

a. If both the values have different signs (one positive and one negative), this guarantees that there is a
root in the range.
b. If both the values have the same sign (both positive or both negative), this guarantees that there is a
root in the range.
c. If f(1) or f(6) has a value of 0, you may stop the search as the root is found.
d. If both of the values are close to zero, this guarantees that there is a root in the range.
e. a) and c)

6. The remaining entries in the first row of the table should be:
a. 4.8553; 0.0207; N/A
b. 4.8553; 0.0207; 3.8553
c. 3.8553; 0.3662; 2.0000
d. 2.0000; 0.0466; 1.0000
e. None of the above

7. The second row of the table should be:


a. 3.0000; 5.0000; 4.0000; 0.0466; 1.0000
b. 1.0000; 2.0000; 1.5000; -0.0297; 0.5000
c. 1.0000; 4.8553; 3.7278; 0.0266; 1.1275
d. 1.0000; 4.8553; 3.7278; 0.0266; -1.1275
e. None of the above

8. After executing the following script file in MATLAB x=3*j; y=x/2*sqrt(-1); z=x+y, the displayed result is
a. 1.5000 – 3.0000 i
b. An error message
c. 3.0000 + 1.5000 i
d. -1.5000 + 3.0000 i
e. None of the above

9. Executing the following code x=[2:4;-1:1; 1 2 3]; y=x(2,:);size(y’), yields


a. 2 2
b. 3 1
c. 2 1
d. 1 3
e. None of the above

3
For Multiple Choice Question 10, please refer to the following plot of the function p(x):

10. For the equation shown in the plot above – assuming Newton-Raphson technique and x0 of 3:
a. The root can only be found by choosing a different x0 value.
b. The root will not be found because of the zero slope region.
c. The root near x = -0.5 will be found.
d. a) and b)
e. None of the above

11. You are performing a Golden Section search in order to maximize a function f. On the first iteration, xL=-2.73,
x2 = 0.88, x1=3.12, xu=6.73, f(x2) =0.22 and f(x1)=-8.71 What are xL and xu on the next iteration?
a. -2.73; 3.12
b. 0.88; 6.73
c. 0.88; 3.12
d. 0.88; 4.49
e. None of the above

12. Examine the following MATLAB code. What is the value of B at the end of the script?

A=2;
for k=0:2:3
A=[A k*A*A];
end
B=C
a. B=2,0,0,0
b. B=2
20
2 00
2000
c. B= 2 0 4 0 8 0 16 0
d. B= 2 2 4 8
e. None of the above

4
𝑙𝑜𝑔10 (𝑥)
Questions 13-14 are concerned with finding a maximum for 𝑓(𝑥) = 2𝑥
− 0.05 that exists between x=1 and x=4;

Using the Golden Section Search, consider the unshaded parts of the following table, with your answers rounded to four
decimal places:

Step xL x2 x1 xU EMAX
1 1.0000 4.0000
2

13. The first row of the table should be:

a. 1.0000; 2.1459; 2.8541; 4.0000; 1.5000


b. 1.0000; 2.3333; 3.6667; 4.0000; 2.0000
c. 1.0000; 2.1459; 2.8541; 4.0000; 3.0000
d. 1.0000; 2.1459; 3.4721; 4.0000; -1.5000
e. None of the above

14. The second row of the table should be:


a. 2.1459; 2.8541; 3.2918; 4.0000; 1.5000
b. 1.0000; 1.8889; 2.7778; 3.6667; 1.3333
c. 2.1459; 2.8541; 3.2918; 4.0000; 0.9271
d. 2.3333; 3.2222; 4.1111; 4.0000; 1.3333
e. None of the above

15. You are performing a Golden Section search in order to maximize a function f. If on the first iteration, xl=4.0000,
and xu=6.0000, how many iterations would be required to reduce Emax to less than 0.01?
a. 14
b. 15
c. 16
d. Less than 14
e. More than 16

16. You are performing a Newton-Raphson root search on f(x)= 1/3 x3 –x2 -3x +5 starting with x0=3 and wish to find
the root near x=1. Is this a good choice, if it is a poor choice, why is it wrong and how would you fix it?
a. No; will result in a divide by zero; make it slightly smaller
b. No; will result in a divide by zero; make it slightly bigger
c. No; you require two first guesses; add a second guess at x1=5.
d. Yes; it should converge to the correct solution
e. No; this function has no roots.

5
Section 2 (10+10 = 20 marks)

a. Write a MATLAB function that will take as input a function f of a vector x, a lower limit xl, and an upper
limit xu and return the (x,y) coordinates of both the maximum and minimum y values in the domain.
The function should return an error if xl is greater than or equal to xu. The first line of the function
should be:

function [xmin, ymin, xmax, ymax] =minmax(f,xl,xu)

6
b. Write a script file or void function file that analyzes the range of the function f(x)= x3 + 2x + 10. It should
repeatedly prompt the user for lower and upper levels for x, plots f(x) between the between those two
limits, then calculates the distance between the maximum and minimum values of f(x). The script
should include a command that prints the value of this distance nicely formatted. The program should
end when the user inputs a negative value for the lower value of x. You may make use of function
minmax.

7
MATLAB Reference:
error ('message') aborts m-file execution with specified error message
fminbnd (f, l, h) locates minimum of function f between l and h
fplot (f, range) plot function f over interval range
range is a 2 element vector. ex: fplot (f, [0, 10])
fprintf ('format', v1, v2, v3...) outputs values using format defined by 'format'
format value fields: %f (fixed point), %e, %E (scientific), %g (general), %d (integer)
width and precision control: %12.3f format controls: \n (newline) \t (tab)
fzero (f, loc) returns a root of function f
if loc is a 2 element vector, looks for a root between loc(1) and loc(2)
otherwise looks for a root in the vicinity of loc
input ('prompt') outputs prompt, returns a value obtained from the user
length (x) returns the length of row or column vector x
linspace(begin, end, n) returns a vector containing n equally spaced values running from
begin to end. if n is omitted 100 values are generated
max(s1, s2) returns the maximum of s1 and s2 (s1, and s2 scalars)
max (v) returns the maximum value in vector v
use [maxVal, maxPos] = max (v) to get both max value and its position
min(...) analogous to max
ones(r, c) creates a matrix r by c matrix of zeroes
ones(size) creates a matrix of zeros with the dimensions contained in 2 element vector size
plot (x, y) plot y values against x values. x are y are vectors of the same length
polyval (p, x) evaluates the polynomial defined by vector p for value x.
if x is a matrix the result will be a matrix of the same size.
roots (p) returns a column vector containing all of the roots of the polynomial defined by
vector p
polyint(p) creates a row vector that represents the integral of the polynomial represented by p
polyder(p) creates a row vector that represents the derivative of the polynomial represented by p
size (x) returns a 2 element row vector containing the dimensions of x (# rows, # cols)
zeros(r,c) creates a matrix r by c matrix of zeroes
zeros(size) creates a matrix of zeros with the dimensions contained in 2 element vector size

Formulas:
f ( xU )( xU − xL ) f ( xi )( xi −1 − xi ) f ( xi )
xR = xU − xi +1 = xi − xi +1 = xi −
f ( xU ) − f ( xL ) f ( xi −1 ) − f ( xi ) f ( xi )

x 0 x 0 log(x 0 / EMAX )
EMAX = N = log2 =
2N EMAX log 2

X 2 = XU − d, X 1 = X L + d , d = ( − 1)( X U − X L )

1+ 5 x 0 ( − 1) N −1
= = 1.6180339887 E MAX = (assuming midpoint)
2 2

Vous aimerez peut-être aussi