Determine the extreme values for the function f(x)

148 views (last 30 days)
Duncan Weakley
Duncan Weakley on 8 Dec 2020
Answered: Rohit Pappu on 28 Dec 2020
Hi there
I need to determine the extreme values for the function f(x) on the interval [0,4]
I am gridlocked with this
I am trying to use vpa, but only get one answer
I need to determine the local maximum and mininum values as well as global
I need this rounded to 4 decimals, and I dont see how simply reading it of the graph can help since 1. the graph give 3 decimals and 2. I dont see that i can place the cursor accurate enough
syms x
total_function = x.*(cos(x.^2)) - exp(sqrt(x))+x.^3 - 4*(x.^2);
f = x.*(cos(x.^2)) - exp(sqrt(x));
g = x.^3 - 4*(x.^2);
dif = diff(x.*(cos(x.^2)) - exp(sqrt(x))) + diff(x.^3 - 4*(x.^2));
vpasolve(dif == 0, x, 4);
extrema = vpa(ans, 6)
xlim([0 4])
Thank you for your help in advance

Answers (1)

Rohit Pappu
Rohit Pappu on 28 Dec 2020
To determine the extrema, optimization toolbox can be used . For example
%% Finding local minima in [0,4] using fminbnd
minima = fminbnd(@(y) y.*cos(y.^2) - exp(sqrt(y))+y.^3-4.*(y.^2),0,4);
%% Finding local minima of -f(x) to get the maxima of f(x)
maxima = fminbnd(@(y) -y.*cos(y.^2) + exp(sqrt(y))-y.^3+4.*(y.^2),0,4);
To determine the global extrema, GlobalSearch can be used

Community Treasure Hunt

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

Start Hunting!

Translated by