MCEN_3030_Computational_Methods___HW_3_Fall_2022

pdf

School

University of Colorado, Boulder *

*We aren’t endorsed by this school

Course

3030

Subject

English

Date

Dec 6, 2023

Type

pdf

Pages

8

Uploaded by EarlChimpanzee3848

Report
MCEN 3030 Computational Methods - HW 3 SOLUTIONS - Fall 2022 Prof. MacCurdy Submission Deadline: September 23rd 2022, Friday @ 11.59pm Submission Guidelines: Follow the homework format and submission instructions in the Syllabus and on the course Canvas site! Read all questions carefully and answer all questions. When in doubt, provide more information rather than less. Question 1 Determine the Highest Real Root of f ( x ) = x 3 6 x 2 + 11 x 6 . 1: 1. (10) Graphically. Use MATLAB. Include a plot in your submission. (a) Full Points: Correct answer (3.04) and code (b) 0.75x Points: Incorrect answer with correct code (c) 0.5x Points: Incorrect answer with error in code (d) 0.25x Points: Incorrect answer with major error in code (e) 0 Points: Incorrect answer/No Attempt 2. (10) Using Fixed-Point Iteration until the approximation error falls below 0.1%. Use an initial value for x i (ie. x 0 ) of 2.9. Generate and submit a table with 2 columns and n rows (where n is the number of total iterations). Your table should have these columns: { iteration number ( i ), x i } 1
(a) Full Points: Answer converges to 3.04 by the 12th iteration within good error ( 0.0010 at final iteration) (b) 0.75x Points: Incorrect answer with correct code OR Correct answer but no tables given (c) 0.5x Points: Incorrect answer with error in code (d) 0.25x Points: Incorrect answer with major error in code (e) 0 Points: Incorrect answer/No Attempt 3. (10) Using Newton-Raphson Method (6 iterations MAX, x 0 =3.5). Generate and submit a table with 2 columns and n rows (where n is the number of total iterations). Your table should have these columns: { iteration number ( i ), x i } (a) Full Points: Answer converges to 3.04 by the 6th iteration (b) 0.75x Points: Incorrect answer with correct code OR Correct answer but no tables given (c) 0.5x Points: Incorrect answer with error in code (d) 0.25x Points: Incorrect answer with major error in code (e) 0 Points: Incorrect answer/No Attempt 4. (10) Using Secant method (6 iterations MAX, x 1 =2.5 and x 0 =3.5). Generate and submit a table with 2 columns and n rows (where n is the number of total iterations). Your table should have these columns: { iteration number ( i ), x i } 2
(a) Full Points: Answer converges to 3.04 by the 6th iteration (b) 0.75x Points: Incorrect answer with correct code OR Correct answer but no tables given (c) 0.5x Points: Incorrect answer with error in code (d) 0.25x Points: Incorrect answer with major error in code (e) 0 Points: Incorrect answer/No Attempt 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Question 2 Part A: (10) Solve the following 3x3 system of equations of the form A x =B using Gaussian Elimination by hand (your submission should be written equations, showing your work): 3 5 8 9 5 12 12 25 30 x 1 x 2 x 3 = 3 15 19 1. Full Points: All steps correct 2. 0.8x Points: One methodology mistake 3. 0.6x Points: Two methodology mistakes/Insufficient work shown 4. 0.4x Points: Three methodology mistakes 5. 0.2x Points: Four or more mistakes 6. 0 Points: Incorrect answer/No Attempt 4
Part B : (10) 1. Write a Gaussian Elimination Solver in MATLAB for a 3x3 OR an NxN system of equations (write this yourself, don’t simply call a built-in Gaussian elimination solver). ( NOTE: In HW3 you have the option of writing the solver for only a 3x3 matrix but in HW4 you will be asked to write the code to solve an NxN matrix, so if you choose to do this now, you’ll get ahead of that question for next time and satisfy the current question.) 2. Apply your code to the above equation in part A and solve for X. Verify the answer from your MATLAB code by comparing it against the answer obtained by hand. Note that when we ask you to “compare” in this course, you should do something quantitative , not just comment. (a) Full Points: x 1 , x 2 and x 3 were found correctly and valid comparison was calculated (b) 0.75x Points: Either x 1 , x 2 or x 3 is correct OR comparison is incorrect/invalid (c) 0.5x Points: All values are incorrect but approach was attempted (d) 0.25x Points: Approach uses built-in MATLAB functions (e) 0 Points: No Attempt 5
Question 3 A Hilbert Matrix is an ill-conditioned square matrix where each element of the matrix H ij is of the form H ij = 1 / ( i + j 1) a) (5)Using a for-loop or a built-in MATLAB function, generate a square 10x10 Hilbert matrix and print it (in your solution). HINT : you can easily control the number of significant digits (and therefore the area consumed) when printing a matrix A, by calling num2str. For example num2str(A,2) will print the matrix A with entries limited to 2 significant digits. (a) Full Points: H Matrix was successfully created (b) 0.6x Points: H Matrix construction is incorrect but attempt is valid (c) 0 Points: No Attempt b) (2) Generate a column vector X actual = 1 2 3 . . . 10 Note that you can use a shorthand notation [1:n]’ to generate the above. (a) Full Points: X actual Matrix was successfully created (b) 0.5x Points: X actual Matrix construction is incorrect but attempt is valid 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
(c) 0 Points: No Attempt c) (5) Taking the Hilbert matrix you generated as H , compute column vector B = H X actual and print it. (a) Full Points: B = H X actual was successfully calculated (See part (d) for solution) (b) 0.6x Points: B = H X actual was incorrectly calculated but attempted (c) 0 Points: No Attempt d) (8) Since you now have matrix H and column vector B , compute X frombackslash through the back- slash operator and X frominverse using the inverse of H and print both. (We’re asking you to solve for X frombackslash using the backslash operator, and X frominverse using the inverse of H ) (a) Full Points: X frombackslash and X frominverse were successfully calculated (b) 0.75x Points: Either X frombackslash and X frominverse was successfully calculated (c) 0.5x Points: Both X frombackslash and X frominverse were unsuccessfully calculated, but attempt was made (d) 0 Points: No Attempt e) (5) Calculate the absolute value of the errors from both methods using norm ( X actual X frombackslash ) or norm ( X actual X frominverse ) and compare your results. Which method is more accurate? (a) Full Points: norms were successfully calculated and compared 7
(b) 0.8x Points: One norm was successfully calculated, but comparison was attempted (c) 0.6x Points: norms were unsuccessfully calculated but comparison was attempted (d) 0.4x Points: norms were correct but no comparisons were made (e) 0 Points: No Attempt f) (5) Using tic-toc, calculate the times taken by your machine to solve the system of equations through each method and compare them. NOTE: when timing the execution of code, it’s a good idea to compute an average time when the execution is short, since other factors like disk access, variable pre-computation, etc can dominate. To do this, use tic/toc as before, but place your code-to-time inside a for loop (which is surrounded by tic/toc) with enough counts to make the computation take several 10’s of milliseconds. This yields more accurate timing results. (a) Full Points: tic-toc was successfully implemented, average times are correct, and comparison is valid (b) 0.8x Points: tic-toc was attempted but one average time is incorrect (c) 0.6x Points: tic-toc was attempted but both average times are incorrect. Comparison is still valid (d) 0.4x Points: tic-toc was attempted but no comparison was made (e) 0 Points: No Attempt 8