필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Fahad Qazi
Fahad Qazi 2021년 2월 19일
답변: Sunand Agarwal 2021년 2월 22일
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에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by