The maximum value assumed by the function on the interval
202 views (last 30 days)
James Browne on 12 Jun 2019
I wrote an example for you which finds the maximum value of f(x) over the specified interval and plots the resuts. Here you go, hope this helps!
%Define the interval over which f(x) will be evaluated
xInterval = [0 1];
%specify resolution of the evaluation
dx = 0.0001;
%Create a vector of x values based on the interval of evaluateion and
x = xInterval(1): dx : xInterval(2);
%Calculate f(x) values
for i = 1:length(x)
fx(i) = sin(5*cos(x(i)))*cos(5*sin(x(i)));
%Find the magnitude and index of the maximum f(x) value and print the
%maximum magnitude to the command window
[M,idx] = max(fx);
fprintf('The maximum value in the given range of x is: %5.4f\n',M)
%Use the index of the maximum f(x) value to find the x value which produced
%the maximum f(x) value
xForMaxFx = x(idx);
%Determine title based on interval of evaluation parameters
titleName = strcat('Maximum f(x) Value over the interval [',num2str(xInterval(1)),',',num2str(xInterval(2)),']');
%Plot f(x) and highlight the maximum value
legend('f(x)','Maximum f(x) value','location','southeast')
Walter Roberson on 12 Jun 2019
Step 1: Plot the function to see visually the approximate peak. Find an approximate interval for the peak; it does not have to be precise at all.
Step 2: Differentiate the function. Solve for a zero of that over the approximate interval that you identified. That gives the location of the peak.
Step 3: substitute the location of the peak into the formula to get the value of the peak.