Determine the maxima and minima of the function

2 ビュー (過去 30 日間)
Maria Shehadeh
Maria Shehadeh 2019 年 3 月 11 日
編集済み: David Goodmanson 2019 年 3 月 12 日
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;

回答 (2 件)

Darpan Verma
Darpan Verma 2019 年 3 月 12 日
%Finding the max value
[maxYValue, indexAtMaxY] = max(y);
xValueAtMaxYValue = x(indexAtMaxY(1));

David Goodmanson
David Goodmanson 2019 年 3 月 12 日
編集済み: David Goodmanson 2019 年 3 月 12 日
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 ./

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by