Hello,
Computing the gradient of a function whose arguments are matrices is a recurring question regarding the usage of Manopt.
This nice blog post should be useful to learn the basic trick:
In a nutshell: the idea is to first compute the Fréchet derivative (or directional derivative) of the function; then to manipulate that expression in order to read off the gradient from it. This will give you the Euclidean gradient of your function, which you can input in Manopt as problem.egrad (notice the "e" in front of egrad, for Euclidean). Manopt will convert that to the Riemannian gradient automatically (for most geometries available; contact us if it's missing in a geometry you are using).
This is also discussed at length in my book, announced here:
Cheers,
Nicolas