a) Write an function that finds the independent variable valueat which a mathematical function is maximized over a specifiedinterval. The function must accept a handle to a function, andevaluate that function at values ranging from x1 to x2 with anincrement of dx. The value returned is the value of x at which themaximum value of f(x) occurs.
Function syntax: xm = xmax(f,x1,x2,dx);
As was the case in the previous problem, this function does notfind the true value of x that maximizes f(x). It only identifiesthe value of x that yields the maximum value of f(x) from amongthose values of x at which the function is evaluated. How closelythis approximates the true maximum point of f(x) will depend on thestep size, dx.
Your function should use only basic arithmetic operations and loopstructures. You may not use any built-in MATLAB functions(e.g., mean.m, sum.m, max.m, min.m, etc.).
Next, you will investigate how the estimated maximum point variesas a function of dx.
b) Write an m-file, ENGR112_HW6_2.m, in which you define thefollowing as an anonymous function.
?(?)=??^2+15??+21.843
Define a logarithmically-spaced vector, dx, of 2000 step sizes,from 10-4… 100, at which xmax.m will be used to approximate themaximizing value of f(x) over the interval of 0 ? x ? 50. Callxmax.m at each value of dx and build a vector of maximizingindependent variable values, xm. In
c) Plot the vector of approximate maximizing values as afunction of step size using a logarithmic axis for the step size.You should see that the approximation converges as step size getssmall enough.