============================================================ Question 1: iteration, swap, function, logical array Given a one-dimensional numeric array, create two arrays sorted in ascending order: one contains all the values at or below the mean; the other contains the values above the mean. Write two functions: $selectsort$ accepts a numeric array as input, sorts it in ascending order in-place (i.e., without creating a new array), and returns the sorted array. You must use the Selection Sort method described below. $split$ accepts a numeric array as input, calls $selectsort$ to sort the array, and returns two arrays: one contains all the values at or below the mean; the other contains the values above the mean. Loops are not allowed in this function. Selection Sort (in ascending order): ------------------------------------ - Start with a numeric array of length N and assume that it is unsorted. - Select the smallest value and put it in the right place, now N-1 elements remain unsorted. - Select the second smallest value and put it in the right place, now N-2 elements remain unsorted. - Continue until all elements are sorted. Matlab reminders: ----------------- Function $mean(x)$ returns the mean of the values in (1-d) array $x$. Function $min(x)$ for a 1-d array $x$ can return both the minimum value and its position (first occurrence). E.g., >> [value,index]=min([4 3 5 2 2 5]) value = 2 index = 4 >> ============================================================ Question 2: Newton's method with a twist The Newton-Ralston method is a modified Newton's method for dealing with multiple roots. The central idea is to apply the Newton's method to a function of the function whose roots we wish determine--the second derivative is needed in addition to the first dervative. Write a function $newtonRalston$ to find the positive real roots of the function f(x) = x^4 - 8.6x^3 - 35.51x^2 + 464.4x - 998.46 using the Newton-Ralston method, described below. Newton-Ralston Method (for root finding): ----------------------------------------- Suppose we wish to find the roots of a function f(x). Define a new function u(x) = f(x)/f'(x) Eq. 1 Function u(x) has the same roots as f(x) does, since u(x) becomes zero everywhere that f(x) is zero. Apply Newton's method to u(x) instead of f(x): delta = x - x(0) = -u(x)/u'(x) Eq. 1 can be differentiated to obtain u'(x): u'(x) = 1 - (f(x)*f"(x))/(f'(x))^2 Algorithm for the Newton-Ralston method: 1. Pick an initial value x 2. Calculate f(x) 3. While tolerance is not met, iterate as follows: - compute f'(x), f"(x), u(x), u'(x) - compute the new value of x, denoted xn - compute the new function value f(xn) For this question, do not worry about the number of iterations. ============================================================ Question 3: Bisection method Write out the algorithm for the bisection method. Try to do this without looking at your project notes. ============================================================