eng77-spring04-mt2-Packard-exam

eng77-spring04-mt2-Packard-exam - E77-Midtenn-2/Name: Page...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: E77-Midtenn-2/Name: Page 1 off) UNIVERSITY OF CALIFORNIA, COLLEGE OF ENGINEERING E77: INTRODUCTION TO COMPUTER PROGRAMMING FOR SCIENTISTS AND ENGINEERS Second Midterm Exam — April 7, 2004 Question Points B 10 CONFIDENTIAL . Notes: 1.Write your name below and on the top left comer of every page. 2.Verify that you have all 6 pages of the test. 3.Please give all your answers only in the spaces provided. 4.You may NOT ask any questions during the exam. 5.Please no cell phones, calculators, or talking during the exam. 6.Please do not leave your seat before the end of the exam. Your NAME: Your STUDENT ID: Your SIGNATURE: SECTION 10r2 (circle your Lecture Section #) Circle your Lab Section (where the graded midterms will be returned next week) #lleW 8-10 #122MW10-12 #13:MW2-4 #14:MW4-6 Etcheveny Etcheverry Etcheverry Etcheverry . #15:TuTh8-10 #16: TuTh 10-12 #17zTuTh12-2 , #18:TuTh2~4 Etchéverry Etcheverry Etcheven'y ‘ Etcheverry F #19: TuTh 4-6 #20: MW 10-12 #2]: MW 2-4 #22: MW 4-6 . Etcheverry Latimer Latimer Latimer E77-Midterm-2/N ame: Pag620f6 A.l. (5 Points) Determine the values of variables 5 and t after execution of the following MATLAB statements: >> A = [1 O 2]; >> B = [3 4]; >> s = O; t = 0; >> for m = 1:2 8 = s + t; for n = 1:3 t = t + A(n)*B(m); end end >> s S :: >> t t = A2. (5 Points) Given the following MATLAB code >> i = 1; j = >> while i < 5 i = i + 1; while j < 3 1; 2:1; 2 = [z i+j] % Note: Output from this line is not % suppressed by a semicolon 3 = J + 1, end end When this code is run, what is printed to the screen? Record your answer below. Add more lines as needed. E77-Midterm-2/Name: Page 3 of 6 B. (10 Points) Given a set of 3 linear algebraic equations with 3 unknowns, —6x1+x2 +2.7C3—l 1 =0 . x1—5x2+2x3=0 2x1+2x2 —7X3 =0 (a) Write the above equations in matrix form Ax = b: (b) Write MATLAB statements to create the necessary arrays: >> A = >>b (c) Write a MATLAB statement that solves the matrix equation that you have developed in part (b): o —»-—-— ll E77-Midterm-2/Name: Page 4 of 6 Cl. (4 Points) Two relationships to evaluate the sum of the first n odd integers are: Sn=l+3+5+...+(2n—l) and 8,, = Sm} + (2n-1) . Using the recursive relationship above, finish the recursive function TOT below so that it calculates the sum of the first n odd integers. function total = TOT(n) if C2. (4 Points) The Tribonacci numbers are defined using the recurrence relation Tn: Tn-l + Til-2 + Tit-3 . where T1 = 1, T2 = 1, T3 = 2. Use the above relationship to complete the iterative function TRIBO so that it returns an array of the first n Tribonacci numbers. The function should work for n 2 4. function t = TRIBO(n) E77-Midterm-2/Name: Page 5 of 6 C3. (6 Points) Consider the following tree structure of letters: B/LN E/ \F / G (a) Write the sequence of letters that results from the preorder traversal of this tree (b) Write the sequence of letters that results from the postorder traversal of this tree (0) List the leaves in this tree E77-Midterm-2/Name: Page 6 of 6 D.l. (2 Points) Check the boxes of all those MATLAB statements below that find one of more roots of the 3 equation x + x =1 as written: ;_]>> find(x"3 + x = 1) [3» roots([l 0 1 —1]) Li>> fzero('x“3 + x — l',[O.l 1]) J» eval('x"3 + x — 1',0.5) D2. (9 Points) Complete the following MATLAB function that solves the equation x3 given tolerance using Newton’s method: function root midterm2_newton(x0,tol) %This function calculates the root of the equation x“3 + x = 1 %using Newton’s method % Inputs: x0 — the initial guess % tol — the error tolerance % Output: root — the calculated root of the equation xold = delta_x = while delta_x xold = end root = +x=1towithina ...
View Full Document

Page1 / 6

eng77-spring04-mt2-Packard-exam - E77-Midtenn-2/Name: Page...

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

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