# What are the derivatives of Squared Exponential kernel function w.r.t. characteristic length scale (Gauss Process)

I'm writing a matlab code to implement Gaussian process. In the book: Gaussian Process for machine learning by Carl Edward Rasmussen and Christopher K. I. Williams, the authors define the squared exponantial function as: $$k(x_p,x_q)=\sigma_f^2exp(-0.5(x_p-x_q)^TM(x_p-x_q))+\sigma_n^2\delta_{pq}$$ Where M matrix, that contains the charactersitic length scales, can be parametrised in three different ways: $$M_1=l^{-2}$$ $$M_2=diag(l)^{-2}$$ $$M_3=\Lambda\Lambda^T + diag(l)^{-2}$$ To optimise the hyperparameters of the Gauss process I shold derivate the kernel function w.r.t. the charactersitic length scales. I can deal with the form given in M1, but I'm heaving a hard time derivating by a diagonal matrix or M3 witch is the sum of a diagonal matrix and a product of lambda and lambda transposed, whitch are also matrixes. Could someone tell me what the derivatives gona be and why, or at least how to get started with it? The mathematical background isn't clear for me in this one.