xuebaunion@vip.163.com
3551 Trousdale Rkwy, University Park, Los Angeles, CA
留学生论文指导和课程辅导
无忧GPA:https://www.essaygpa.com
工作时间:全年无休-早上8点到凌晨3点

微信客服:xiaoxionga100

微信客服:ITCS521
M6803 Computational Methods in Engineering Assignment 2 – Curve fitting with MATLAB Submission Date: Friday, 8 October 2021 Submit a softcopy via the course site, using the same link for this handout. Question 1 Write a program to evaluate an arithmetic expression given the equivalent postfix string of the expression. Provide at least three test results with different postfix strings in your submission. Question 2 Write a program 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 (Numerical Methods for Engineers by Chapra and Canale, 6th Edition, Example 14.4, P381): f(x, y) = 2xy + 2x -x2 – 2y2, with the initial point at (-1, 1). 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 3 Write three separate programs to approximate the cosine curve between - and 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 for the algorithms, but 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 uniformly distributed data points: 5, 15, and 50. Study the results 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, use “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 and derive the curve equation. 2. For each case, using 15 data points only, investigate the behaviour of the fitted curves when there are some small errors in the input data. Create the errors artificially by changing some (or all) of the original sine values of the curve slightly for the given angles. This error can be positive or negative and should be random, and therefore different for every point. 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. (In case you wonder how to apply the error, here is an example. Note that the absolute maximum of the sine of an angle is 1. Hence a bound of 2% in the error means a maximum error of 1*0.02 = 0.02. Hence the error value is within 0.02, and it should be generated randomly, using a random number generator.) 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 programs and report for the questions 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.