Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Matlab function that performs parabolic interpolation to find the one-di

ID: 3866329 • Letter: W

Question

Write a Matlab function that performs parabolic interpolation to find the one-dimensional optimum. The function prototype (i.e. first line of your file) should be

function [x3, f3] = parabolicInterpolation(x, funcName)

Use the Matlab function str2func to convert a string to a function. Therefore, a string variable will be sent as funcName. Set the stopping criterion to be a<1e-6.

You can test your function with example 13.2

>> [x, f]=parabolicInterpolation([0 1 4],'myFunc')
x = 1.4275
f = 1.7757

In this case, there would be an additional Matlab file called myFunc.m that contains the function for which the optimum is being found. Your function should error test at the beginning to make sure the optimum appears between the lower and upper bounds of the initial guess vector sent. For the example above, check that there is a maximum between myFunc(0) and myFunc(4).

Explanation / Answer

function xincrement = findpeak3(y)
% FINDPEAK - parabolic interpolation of peak location given 3
equally-spaced points
% Returns a relative delta-x value to be added to the x-value of y(2).
% i.e., xpeak = x(2) + findpeak(y) * (x(3) - x(2));


xincrement = 0.5 * (y(1) - y(3)) / (y(1) - 2 * y(2) + y(3));
%end findpeak

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote