OK, I'll try provide an answer as good as possible:
The gradient can have two types of maxima : (1) local maxima, inside the domain, or (2) maxima on the border of the domain. If you have a function of just one variable, f(x) : { a ≤ x ≤ b }, as you wrote, then
for (2) you just have to compute f'(a) and f'(b) (if x is multi-dimensional you must run along all the border),
for (1) we know that these maxima will happen in points x where f''(x) = 0.
Of course that depends on f, a and b, and in general there is no way of knowing which of these extrema is the largest, so all of these must be computed to find which is the largest one.
Consider e.g. f(x) = x sin(x) which oscillates with increasing amplitude, so depending on where you stop the gradient in a as well as in b may be zero, small or huge, positive or negative, and all of these cases occur infinitely often. So you definitely must compute both of the border values, in addition to checking the local maxima.
Also in your example of the function f(x) = x (x-1) (x+1) = x^3 − x, f'(x) = 3 x² − 1, you can see that you have a locally maximum gradient in 0 (where the gradient is f'(0) = −1, and I assume you mean "maximum" in absolute value, otherwise there's no local maximum) as long as 2 < a < 0 < b < 2; but when a < −√(2/3) or b > √(2/3) then the maximum will be f'(x) = 3x² − 1 > 1 at x = a if |a|>|b| or at x = b if |b|>|a|.
All of these can be computed analytically (sometimes) or numerically (always). Software like Maple and Mathematica (and WolframAlpha) and Sagemath (free) or Xcas (free) and Python (with SymPy) can compute the derivatives f' and f'' and solve f''(x) = 0 for nontrivial functions f involving polynomials and sin, log, exp … quite often, but not always. When they can't find an analytical solution, they can "always" find numerical solutions. See for example https://docs.sympy.org/latest/modules/solvers/solvers.html#sympy.solvers.solvers.nsolve
See here for a small Python program that solves your problem and which you can modify to use it for a different function or domain (a,b) : https://trinket.io/python3/e92039b3b3
Actually, your method using colors is a kind of numerical solution, but it involves guesswork on the exact point where the maximum lies. Maybe you actually could theoretically also use desmos to find (approximately) the maximum gradient, by displaying values of f''(x) and "scanning" these over the domain a ≤ x ≤ b, to find its zeros and look at the values of f' = grad f there.
1. For a difficult question the bounty should be much larger. 2. Are you dealing only with functions of one variable? 3. Are you always restricted to a closed domain like [a,b]?
1. I’m not sure how hard this question is. I am studying towards my second year of A levels, it may just be something we haven’t covered yet. 2. I might not understand what you mean but things like an ellipse where you have x and y, don’t worry about that, just in terms of x. 3. Yes the function is always restricted to the domain, between a and b. If it was unrestricted I would have thought it would make it harder for some graph though where the gradient tends to infinity.
Do you have formulas for your functions in terms of x?
Sorry I don’t really understand what anyone is talking about. I want to be able to put things like polynomials, cos, cosh, all that stuff into it and it works.
What do you mean by "it works"? If you have explicit formulas for your functions, you can find the maximum points of $f'$ by computing the second derivative $f''$. Is this acceptable?
It's not clear what you want to do, sadly. But if you care only about the maximum of f'(x), you could take its derivative, set it to zero, find critical points and evaluate those critical points and the endpoints of the interval [a,b] to find its maximum. Because you are only working in an interval [a,b] you are guaranteed to find a maximum for f'(x) like this.
Sorry. Yes this is what I want it to do. I’m just not sure how to implement it on the graph.
I have formulas for my functions
You don't have to graph the functions to find the maximum of f'. Is that ok? It would be extremely easier as long as you can compute and solve f'' (x)=0.
I can give more details if that's ok with you.
Desmos doesn’t allow you to do that
I want to be able to set f(x) to anything I want and it calculates the second derivative, sets it to 0, solves it… I understand I could do this manually but I want this to be something it calculates and does itself
Desmos is not the right way to do this then. This problem is indeed very challenging, and needs a much more sophisticated approach.
I will try to provide an answer as good as possible, but I also don't think desmos is the right tool to deal with this. I will give you better proposals. Also, your desmos graph (link) appears empty to me.
Oh god 🤦♂️ that would help. Hopefully what I am trying to do will be a more more clear when you see the graph. I have updated the link
If anyone is interested, I actually managed to get this working… to some extent. I made a list of the gradient at all plotted points, sorted it from smallest to largest, got the last value. I understand this is not going to be the true maximum gradient and only an estimation but it is close enough that for what I wanted it to do, it works fine. It doesn’t work for all graph. For some values of an and b the values of the sorted gradient list become undefined for some reason
https://www.desmos.com/calculator/jhwatkoi6j