I am trying to find the maximum $y$-value of the fourth derivative of the function $f(x) = \frac{1}{1.1+cos(x)}$.
I am limited to real numbers. I know that the answer should be 6100 and occurs at $x_0=-\pi$ and $x_1=\pi$.
I am having problems trying to to write code in MATLAB to solve the problem. I am still relatively new to MATLAB, so it might be the way I go about trying to find multiple critical points.
Logically, what my program does is that it looks at the function $f(x)$, finds the fourth derivative, finds the critical points looking at the fifth derivative, and then substitutes those values into the fourth derivative to find the maximum $y$-value.
Here is what I have so far:
syms x
format long
fx = 1/(1.1 + cos(x));
for i = 1:4 % Computes fourth derivative of fx
fx = diff(fx);
end
fourth_derivative = fx;
fx = diff(fx);
fifth_derivative = fx;
% Set fifth_derivative = 0 and solve
crit_pts = real(solve(fifth_derivative))
% This is the y value that my code thinks is the maximum
max_y = eval(subs(fourth_derivative,crit_pts))
% This is the correct value of the maximum of y
correct_max_y = eval(subs(fourth_derivative,pi))
% Plotting to show that my code can't find the max
ezplot(fourth_derivative)
hold on
plot(crit_pts, subs(fifth_derivative,crit_pts), 'ro')
title('Max and Min of fourth derivative')
axis([-6 6 -100 6200])
hold off
Reliably finding multiple roots is challenging. As many of these roots can't be found analytically for your system, they must be found numerically.
Matlab's
solvefunction is a general method. It tries many things in order to return solutions, but it does not guarantee that it will return all solutions (indeed, your system, being periodic, has an infinite number). I recommend reading the documentation forsolve. The first thing it tries is to find an exact symbolic solution. In your case, it appears that it found one root at zero, but it did not find any other so it stopped. If it had not found any solution it would have attempted to find a root numerically (similar to callingvpasolvedirectly).What can you do? In Matlab you can take advantage of some of the feature of MuPAD that have not yet been fully-integrated into the Symbolic Math toolbox. In particular, the
numeric::realroots(documentation) andnumeric::solve(documentation)functions are of interest. Here's an example of how you might use the latter for your system:which returns roots at
Also, if you can bracket the root you're interested in, you can use
vpasolveto find it, e.g.:You can use a similar approach to find the root numerically via
fzero.