How can i get local maxima,minima and inflection point displayed in the graph

5 vues (au cours des 30 derniers jours)
Fahad Qazi
Fahad Qazi le 19 Fév 2021
hi, i am trying to write a function using fplot to plot a function and its first derivative and second derivative. i am able to plot the graph by simply running the function but how can i display the points automatically that indicate which is local maxima, minima and inflection point. i have a picture to show what i am getting at this moment. i am a begginner here for matlab
my code is here
function Output = Q2
figure;
lmaxPlot=[];
lminPlot=[];
inflPlot=[];
verAsymPlotBottom=[];
syms x;
func = (2*x^4 - 40*x^3 + 299*x^2 - 989*x + 1219)/(x^2 - 10*x + 23);
% place your work here
assume(x,'real');
firstdiff=diff(func); %we differentiate here with respect to x
disp(firstdiff);
seconddiff=diff(firstdiff);% we differentiate here with respect to x the result of firstdiff;
fplot1 = fplot(func,[2,8],'b-'); %plot the first function without derivation.
ylim([-15,30]);%set the Ylimits of the graph.
hold on %avoid function override
fplot2 = fplot(firstdiff,[2,8],'r-'); %plots the second function
ylim([-15,30]);
hold on %avoids function override
fplot3 = fplot(seconddiff,[2,8],'y-'); %plots the third function
ylim([-15,30]);
hold on
% firstdiffsol = solve(firstdiff == 0,x, 'Maxdegree', 4);
% lmaxPlot= vpa(firstdiffsol,6);
% plot(lmaxPlot,subs(func,lmaxplot),'ro');
% hold on
fplotH = {fplot1;fplot2;fplot3};% here we are passing an array of output for fplots. in which all values passed are plots of function in same graph.
legendArray = {'f(x)',"f'(x)","f''(x)"};
legendArray = [legendArray, {'Local Minima'}];
legendObject = legend(legendArray);
set(legendObject, 'Location', 'north')
Output = {fplotH; lmaxPlot; lminPlot; inflPlot; verAsymPlotBottom};
end

Réponses (1)

Sunand Agarwal
Sunand Agarwal le 22 Fév 2021
Hello,
Please refer to the following link for an example of showing the critical and inflection points in a MATLAB graph:
Hope this helps.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by