MATLAB: Determine the intervals on which the function f(x) is increasing and decreasing

decreasingderivativefunctionincreasingintervalintervals

Hi there
I am struggeling to compute this
I need to get the intervals where f(x) is increasing rounded to 4 decimal values as output
I realise it will be where f'(x)>0 and f'(x)<0
this is what i got sofar:
clf
f = sinh(x.^2);
h = sqrt(cosh(x)-1);
fplot(diff(f)-diff(h))
grid on
ylim([-5 5])
xlim([-5 5])

Best Answer

syms x
f = sinh(x.^2);
g = diff(f);
sol = solve(g == 0, 'returnconditions', true)
sol = struct with fields:
x: [3×1 sym] parameters: [1×1 sym] conditions: [3×1 sym]
sol.x
ans = 
sol.conditions
ans = 
by inspection: (-1)^(1/4) is complex-valued. sqrt(k+1/2) is complex valued for integer k <= -1, and complex times the complex root of unity is potentially real-valued. For integer k = 0 and upwards, sqrt(k+1/2) is real valued, and real times the complex root of unity is always complex-valued.
Therefore, we only need to consider k = -1 and less
assume(sol.parameters, 'integer')
curl = simplify(subs(diff(g), x, sol.x))
curl = 
The signs of those are the important parts: positive for local minima, negative for local maxima. For negative k, 2*k+1 is always negative, and -2*pi is always negative, so the sign comes down to the sign of (-1)^k which is negative for odd k (local maxima) and positive for even k (local minima)
sol.x tells you where the critical points are; curl tells you the maxima / minima. If you are at a local maxima, then everything to the next local minima (greater x, so decreasing k) is decreasing; if you are at a local minima, then everything until the next local maxima (greater x, so decreasing k) is increasing.
Related Question