Determine the extreme values for the function f(x)

39 次查看(过去 30 天)
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)
fplot(total_function)
xlim([0 4])
Thank you for your help in advance

回答(1 个)

Rohit Pappu
Rohit Pappu 2020-12-28
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

类别

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