This Is an Open-Book Test. There Are 4 Problems in Total

This Is an Open-Book Test. There Are 4 Problems in Total

<p> ME211 Midterm 1 (10/8/2004)</p><p>NAME: ______</p><p>This is an open-book test. There are 4 problems in total. You have 50 min to finish the exam. Clearly mark your final answers. To ensure consideration for partial scores, write down intermediate steps where necessary.</p><p>Good luck!</p><p>Problem Score 1 2 3 4 Total</p><p>1 1. Use any root finding method you have learned to find the zero (between 0.5 and 1) of y  x 3  3x 2 1 to two significant digits. State the name of the method you have used. (10 points)</p><p></p><p>2 2. Read the following Matlab program and answer the questions.</p><p> function I = anonym(f,a,b,n) h=(b-a)/n; S=feval(f,a); for j=1:2:n-1 x(j)=a+h*j; S=S+4*feval(f,x(j)); end for j=2:2:n-2 x(j)=a+h*j; S=S+2*feval(f,x(j)); end S=S+feval(f,b); I=h*S/3</p><p>(a) What is the purpose of this function anonym? (2 points) (b) If the file myfunc.m contains the following statements</p><p> function f=myfunc(x) f=exp(-x^2);</p><p>What is f after the following statement is executed in the command window? (6 points)</p><p> f=anonym(‘myfunc’,0,1,2)</p><p>(c) Is the following statement the proper way of using anonym? Why? (2 points)</p><p> f1=anonym(‘myfunc’,0,1,3)</p><p>3 3. The following Matlab function for Euler’s method has some errors. Identify and correct them. (10 points)</p><p> function [x,y]=Euler(f,a,b,y0,n) %solve y’=f(x,y) with initial condition y(x=a)=y0 %using n steps of Euler’s method; step size h=(b-a)/n h=(b-a)/n; x=(a:h:b); y(a)=y0; for j=1:n+1 y(j)=y(j-1)+h*feval(f,x(j-1),y(j-1)); end</p><p>4 4. (a) Write down the third-order Taylor series of ln(1+h) (up to h3) and also its remainder. (5 points)</p><p>(b) For small oscillations, the period of a pendulum can be described as l T  2  where g=9.8 m/s2 is the local acceleration of gravity and l is the length g of the pendulum. What relative error would be introduced to T if the measurement of l has a relative error of 1% (say l 1 0.01m.) (5 points) </p><p></p><p>5 ME211 Midterm (10/26/2005)</p><p>NAME: ______</p><p>This is an open-book test. There are 4 problems in total. You have 50 min to finish the exam. Clearly mark your final answers. To ensure consideration for partial scores, write down intermediate steps where necessary. The average score in this exam is 30.5/48. Good luck!</p><p>Problem Score 1 2 3 4 Total</p><p>6 2 5. Use Newton’s method to solve x 1  0. Starting from x 0  0.2 , show the results of the first 2 iterations. (10 points)</p><p>Solution:  </p><p> y  f (x)  x 2 1; y' f '(x)  2x.</p><p>2 x2  0.2 , y0  0.2 1  0.96; y'0  2 0.2  0.4</p><p>So </p><p> y0  0.96 x1  x0   0.2   2.6 y'0 0.4 2 y1  2.6 1  5.76;</p><p> y'1  2 2.6  5.2 Then</p><p> y1 5.76 x2  x1   2.6   1.492 y'1 5.2</p><p>7 2. Use Gauss-Seidel iteration algorism to solve the following system of linear equations,</p><p> 5x1  x2  7  x1  4x2  x3  12 .   x2  2x3  8 (a) In matrix notation rewrite the above equations in a form suitable for iteration, i.e., x=Cx+D. What are C and D? (7 points)</p><p>x10  1  (b) Starting from the initial value x20  1,  x30  1 write down the result after one iteration (round to 3 significant digits). (7 points)</p><p>Solution:</p><p>(a) Rewrite the above equations in this form:</p><p>5x1   x2  7  4x2   x1  x3 12  2x3   x2  8  1  0  0 7 x (n)   5 x (n1)  1   1 5  (n)  1 1  (n1)     x2    0  x2   3 (n)  4 4 (n1) x  x  4  3   1  3    0  0    2 </p><p>So, 1 7 x (1)   x (0)   1.20 1 5 2 5 1 1 x (1)   x (0)  x (0)  3  2.45 2 4 1 4 3 1 x (1)   x (1)  4  2.78 3 2 2</p><p>8 3. Write a Matlab function for numerical integration using the two-point Gaussian b quadrature formula. Assume the integral has the form  f ( x ) d x . (10 points) a Solution: 1 n The basic form of Gaussian quadrature is: f (x)  ci f (xi ) . For a general 1   i1 interval[a,b], we have to transform the integral in [a,b] to[1,1], that is : </p><p> b 1 f (x)dx  f (At  B)d(At  B) , a 1 where x  At  B  b  a A  a  A  B  2  b  a B  b  A  B  2 So, if we set n=2, b 1 b  a b  a 1 b  a b  a 1 b  a f (x)dx  A f (At  B)dt  [ f (  ( )  )  f (  ( )  )] a 1 2 2 3 2 2 3 2</p><p>Matlab function:</p><p> function I=Gauss_2p(f,a,b) A=(b-a)/2; B=(b+a)/2; I=A*(feval(f,-A/sqrt(3)+B)+feval(f,A/sqrt(3)+B));</p><p>9 4. Solve the following ODE y' x y, 0 x1, y(1) 2. Notice here the ‘initial’ condition is given at x=1, not x=0. a. Can you still use the following Matlab function for Euler’s method, discussed in the class and attached below, to solve this problem? If yes, write the Matlab line to call this function for the above problem, assuming the derivative is saved in a function named f_midterm and 10 steps will be used. (4 points) b. What is y(0) if it is solved by midpoint method with 1 step? (10 points) [If you can’t do the problem with the initial condition at x=1, do the above problem with the initial condition y(0)=-1 and find y(1).]</p><p>Matlab function for Euler’s method function [x,y]=Euler(f,x0,x1,y0,n) h=(x1-x0)/n; y(1)=y0+h*feval(f,x0,y0); x=(x0+h:h:x1); for i=2:n y(i)=y(i-1)+h*feval(f,x(i-1),y(i-1)); end x=[x0 x]; y=[y0 y];</p><p>Solution: a. Yes, we can.</p><p> x0=1;x1=0;n=10;y0=-2; [x,y]=Euler(‘f_midterm’,x0,x1,y0,n);</p><p> b. Midpoint method: h  1</p><p> k1  hf (1,2)  1 (1 2)  1; h k 1 1 k  hf (1 ,2  1 )  1 (1  2  )  1; 2 2 2 2 2</p><p> y(0)  y(1)  k2  2 1  1</p><p>If you have questions or there are mistakes in my solution, please inform me as soon as possible. Thanks By Rui Yan</p><p>10 Scratch paper</p><p>11</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us