Determine the maxima and minima of the function
6 views (last 30 days)
Show older comments
I cant seem to get the right values for x and y max and min.
The correct values are p09xmin = 1.2464 p09ymin = -0.1654 p09xmax = 2.7536 p09ymax = 0.1654.
figure;
% f(x) = (x-2)/((x-2)^4 +2)^1.8
F = @(x) ((x-2)/((x-2).^4 + 2).^1.8);
fplot(F,[0 9]);
xlabel('x');
ylabel('y');
title('p9'); % FIX THIS ENTIRE PROBLEM
ylim([-0.2, 0.2]);
hold on;
p09xmax = fminbnd('-((x-2)/((x-2).^4 + 2).^1.8)',2.3,2.6)
p09xmin = fminbnd(F,1,1.3)
p09ymax = fminbnd('-((x-2)/((x-2).^4 + 2).^1.8)',0.15,0.2)
p09ymin = fminbnd(F,-0.2,-0.15)
plot(p09xmax,p09ymax,'ok');
plot(p09xmin,p09ymin,'or');
txt1 = ['(', num2str(p09xmax,'%0.4f'),',', num2str(p09ymax,'%0.4f'),')'];
txt2 = ['(', num2str(p09xmin,'%0.4f'),',', num2str(p09ymin,'%0.4f'),')'];
tx1 = p09xmax + 0.1;
tx2 = p09xmin + 0.1;
text(tx1,p09ymax,txt1);
text(tx2,p09ymin,txt2);
hold off;
clear F txt1 txt2 tx1 tx2;
0 Comments
Answers (2)
Darpan Verma
on 12 Mar 2019
%Finding the max value
[maxYValue, indexAtMaxY] = max(y);
xValueAtMaxYValue = x(indexAtMaxY(1));
0 Comments
David Goodmanson
on 12 Mar 2019
Edited: David Goodmanson
on 12 Mar 2019
Hi Maria,
for a fumction f(x), fminbnd determines the value of x where the minimum occurs. You would have found p09xmax if your lower and upper limits 2.3 and 2.6 had bracketed the x value where the maximum occurs. Your limits didn't do that, so fminbnd got as close as it could, which was 2.6. Try, say
p09xmax = fminbnd('-((x-2)/((x-2).^4 + 2).^1.8)',2,3)
Then you can get p09xmin with
p09xmax = fminbnd('((x-2)/((x-2).^4 + 2).^1.8)',a,b)
where a and b are suitable x values to bracket the location where the minimum occurs.
At this point you are done with using fminbnd. To obtain p09ymax, you can just do a function evaluation at p09xmax. Similarly for p09ymin.
Incidentally, the warning messages about the anonymous function F are telling you that in the function definition,
/ should be ./
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!