Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

MSE 260

Homework 4

Spring ‘23

Answer all questions. Show all calculations, define all necessary terms, and show reasoning to receive credit. Absolutely no credit will be given for guessing! No handwritten/scanned work will be accepted. All work must be typed in whatever preferred format and all implemented MATLAB code must be included in your solutions. Submit your homework as a single pdf document.

Problem 1: Forward and Backward Difference Approximations (Chapra, Problem 4.16)

Use forward and backward difference approximations of O(h) and a centered difference approximation of O(h2) to estimate the first derivative of

f (x) = 25x3 6x2  + 7x 88

Evaluate the derivative at x = 2 using a step size of h = 0.25. Compare your results with the true value of the derivative. Interpret your results on the basis of the remainder term of the Taylor series expansion.

Problem 2: MATLAB (Chapra, Problem 4.4).

For computers, the machine epsilon e can also be thought of as the smallest number that when added to one gives a number greater than 1. An algorithm based on this idea can be developed as

Step 1: Set e = 1.

Step 2: If 1 + e is less than or equal to 1, then go to Step 5. Otherwise go to Step 3.

Step 3: e = e / 2

Step 4: Return to Step 2

Step 5: e = 2 ´ e

Write your own M-file based on this algorithm to determine the machine epsilon. Validate the result by comparing it with the value computed with the built-in function eps.

Problem 3: Derive and average method (Chapra, Problem 3.13).

The “divide and average” method, an old time method for approximating the square root of any positive number a, can be formulated as

x + a

x =

2

Write a well-structured M-file function based on the while…break loop structure to implement this algorithm. At each step estimate the error in your approximation as

ε = xnew xold x

new

Repeat the loop until e is less than or equal to a specified value. Design your program so that it returns both the result and the error. Make sure that it can evaluate the square root of numbers that are equal to and less than zero. For the latter case, display the result as an imaginary number. Test your program by evaluating a = 0, 2, 10 and -4 for ε = 1 × 10 4 . Hint: This is similar to the IterMeth function discussed in class.