Guaranteed Higher Grade!

Free Quote
Answered

Question 1

Write a program, in MATLAB or Python to perform optimization of a 2D polynomial function f(x, y) using the method of steepest descent or ascent.

The algorithm is given in the textbook but write it down in pseudo-code first. Use the method of Golden Section for the optimization problem in 1D that is produced as a step in the solution. You will also need to have a function that takes partial differentials of f(x, y) with respect to x and y. But before all that, you will have to devise a method to represent a general polynomial in 2 variables.

Test your program using this function in the textbook (p373, Q14.8): with the initial point at (0, 0). Plot the function as a 3D surface and the steps your program takes to reach the optimum point. Mark the optimum point with a marker (such as a cross).

Then test it again using two different functions of your own choice.

Once you have completed this exercise, you would have understood the method of steepest ascent very well.

(I am restricting f(x, y) to a polynomial function to simplify the problem. You are welcome, however, to extend it to non-polynomial functions.)

Please write your code clearly, providing comments and using meaningful variable names

Question 2

Write three separate programs to approximate the sine curve between 0 and 2? using curve fitting by

(a) a polynomial curve of power 4;

(b) a cubic spline;

(c) Lagrange’s interpolating polynomial or Newton’s interpolating polynomial.

You may refer to the textbook (Numerical Methods for Engineers by Chapra and Canale) for the algorithms, but I expect that you can work that out yourself given the lecture materials. For each of the three cases, you should generate points on the curve at regular intervals and use these points as your data points for the curve fitting. Use the same set for each of the three approximations.

1. For each case, investigate the quality of the fitting with three different number of data points: 5, 20, and 50. You can study that qualitatively by plotting the original curve on top of the fitted curves, together with the curve of the difference between the two. Compare the results of the three different curve types, and comment on your observations. For the case of the cubic spline, you may consider the use of “natural splines” which has zero curvature at the free ends of the curve (curvature is a function of the second derivative of the curve). You can use this as a part of the boundary conditions of the curve.

2. For each case, for the case of 20 data points only, investigate the behaviour of the fitted curves when there are some errors in the input data. You can manufacture the errors artificially by changing some (or all) of the original values of the sine curve slightly for the given angles. This error should be random, and therefore different for different points. Your investigation should be systematic, by studying different error magnitudes progressively. This means varying the

bound of the error magnitude in each study. This can be an endless investigation if you are to vary the data many times. So let’s keep it to three error bounds of 2%, 10% and 20%. Comment on the results.

You should produce a report showing your results and commenting on the above investigations, supported by graphical outputs. Of course, your report should show the data you use for every case.

Please submit your program and report for each question through the Assignment page in the course site, explaining how your program works, including how to run the program and the data input required, plus the test data and results. You may submit a hard copy of your report if you prefer. However, you still need to submit the programs online

Solved by qualified expert