Build a program solves a 2D unconstrained optimization problem. Your code will find the local maximum of a 2D function f (x, y) using the gradient ascent with inexact (backtracking) line search method. You will use the Armijo condition to ensure the function increases by a minimum amount at each step.
The input arguments are the anonymous function f, the initial guesses xi and yi, error tolerance tol, Armijo condition constant sigma, and backtracking constant beta. You will take steps toward the local maximum value until the following termination criterion is met (Listed on end of screenshot page 1)
The outputs of calcMaxStudent are the two-column array xypos that contains the x- and y-coordinates at each step, the number of steps numsteps required to achieve the termination criterion, and the number of function evaluations numfneval (every time your invoke f (x, y), a counter variable should increase by 1).
Additionally, you must create a contour plot of the function and show the path traveled.
- Use circles to indicate the location of each step, a line connecting the steps, and a colorbar to indicate the value of the contour lines.
- The x and y ranges for the contour plot should be 20% larger than the largest magnitude value of each coordinate. For example, if the largest magnitude x-coordinate is -10 and the largest magnitude y-coordinate is +3, then the x range should be [-12, +12] and the y range should be [-3.6, +3.6].
- The spacing between data points used for the contour plot (dx and dy) should scale too. If you set the spacing to a very small value, it may take a very long time to generate the plot. If you set the spacing to a very large value, the contour plot may look choppy. You can scale the spacing by setting its value to some fraction of the total range. For example, once you establish the x-range, then dx can be x-range/100 (experiment with different denominators until you get a contour plot that looks nice).