フィルターのクリア

How would I plot this and then achieve minimum and maximum.

1 回表示 (過去 30 日間)
Tom
Tom 2023 年 11 月 21 日
コメント済み: Les Beckham 2023 年 11 月 24 日
This is the equation
My script looks like this and fails
x=0:0.1:15
y=(x)^3/3-11(x)^2/2+24x
plot(x,y)
Not yet got my head around MatlB
  1 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 21 日
移動済み: Dyuman Joshi 2023 年 11 月 21 日
Look into
max, min - for global extremum
islocalmax, islocalmin - for local extremum

サインインしてコメントする。

採用された回答

Les Beckham
Les Beckham 2023 年 11 月 21 日
編集済み: Les Beckham 2023 年 11 月 21 日
x = 0:0.1:15;
% y=(x)^3/3-11(x)^2/2+24x << you were missing multiplication operators *
% and the powers need to be .^ (element-wise operator) instead of ^ (matrix
% operator)
y = x.^3 / 3 - 11*x.^2 / 2 + 24*x;
plot(x, y)
grid on
xlabel x
ylabel y
fprintf('min(y) = %f; max(y) = %f\n', min(y), max(y))
min(y) = 0.000000; max(y) = 247.500000
Also, if you are just getting started with Matlab, I would highly recommend that you take a couple of hours to go through the free online tutorial: Matlab Onramp
  2 件のコメント
Tom
Tom 2023 年 11 月 24 日
Thanks, that OnRamp is really well setup!
Les Beckham
Les Beckham 2023 年 11 月 24 日
That's good to hear. I hope it was helpful.

サインインしてコメントする。

その他の回答 (1 件)

Sam Chak
Sam Chak 2023 年 11 月 21 日
Hi @Tom
The cubic function does not have global extrema, but it does have a local maximum point and a local minimum point. Are you looking to plot something similar to this?
%% Find local max and local min over a certain range
y = @(x) x.^3/3 - 11*x.^2/2 + 24*x;
xlocal = linspace(1, 10, 90001);
ymax = max(y(xlocal))
ymax = 31.5000
idx1 = find(y(xlocal) == ymax);
xmax = xlocal(idx1)
xmax = 3
ymin = min(y(xlocal))
ymin = 10.6667
idx2 = find(y(xlocal) == ymin);
xmin = xlocal(idx2)
xmin = 8
%% Plot function over a predefined range
x = 0:0.1:15;
plot(x, y(x)), grid on, hold on
plot(xmax, ymax, 'o', 'markersize', 12, 'linewidth', 2)
plot(xmin, ymin, 'o', 'markersize', 12, 'linewidth', 2)
xlabel('x'), ylabel('y')
xt = [xmax-1 xmin-1];
yt = [ymax+15 ymin+15];
str = {'local max','local min'};
text(xt, yt, str)
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 21 日
I'm a curious as to why you chose to use max() and min() instead of islocalmax() and islocalmin().
Sam Chak
Sam Chak 2023 年 11 月 22 日
Sometimes, I'm accustomed to using functions with the same name in other software. It's good that you introduced islocalmax() and islocalmin().

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by