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

5 次查看(过去 30 天)
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

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by