How would I plot this and then achieve minimum and maximum.
Afficher commentaires plus anciens
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 commentaire
Dyuman Joshi
le 21 Nov 2023
Déplacé(e) : Dyuman Joshi
le 21 Nov 2023
Look into
Réponse acceptée
Plus de réponses (1)
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))
idx1 = find(y(xlocal) == ymax);
xmax = xlocal(idx1)
ymin = min(y(xlocal))
idx2 = find(y(xlocal) == ymin);
xmin = xlocal(idx2)
%% 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 commentaires
Dyuman Joshi
le 21 Nov 2023
I'm a curious as to why you chose to use max() and min() instead of islocalmax() and islocalmin().
Sam Chak
le 22 Nov 2023
Sometimes, I'm accustomed to using functions with the same name in other software. It's good that you introduced islocalmax() and islocalmin().
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

