Second order derivative of log of vector

3k Views Asked by At

I have a vector of size $n$ x $1$ named $\alpha$. Let $f(\alpha) = u\cdot\mathbf 1^{\!\top}ln(\alpha)$ where $u$ is scalar.

What is the $f'(\alpha)$ and $f''(\alpha)$ and equivalent Matlab code?

According to me the first derivative is

$$f'(\alpha) = u/\alpha$$

and equivalent MATLAB code is --

f_a_1 = u ./ a

and for the second derivative

$$f''(\alpha) = u\cdot(Diag(\alpha)*Diag(\alpha))^{-1}$$

Equivalent MATLAB code is

f_a_2 = u*inv(diag(a)*diag(a))

Is my inference correct?

1

There are 1 best solutions below

0
On BEST ANSWER

Let $\alpha =(\alpha_1,\alpha_2,\dots,\alpha_n)$ You probably (see the note below to understand the doubts) defined function $f:\mathbb{R}^n\to \mathbb{R}$ $$f(\alpha)=f(\alpha_1,\alpha_2,\dots,\alpha_n)=u\sum_{i=1}^n \ln\alpha_i$$ therefore

If you need a vector gradient of $f$ (a vector of partial derivatives), then you denote it as $$\nabla f=\left(f_{\alpha_1},\dots,f_{\alpha_n}\right)=\left(\frac{u}{\alpha_1},\dots,\frac{u}{\alpha_n}\right)$$ and compute it in matlab as

u./a

if you looking for a total derivative of $f$ it is defined as $\nabla f\cdot \alpha$ and in your case is equal to $u n$ and another differentiation will be $0$.


You can do

-u./(a.^2)

in matlab (without converting it to diagonal matrices etc), but this is not a second derivative of your function.

I would say you have to really clarify your question.


Note, the $\ln$ of a matrix is defined for $n\times n$ matrices, so the notatoins of $\ln$ of vector are incorrect and misleading.

The truth is that $$\exp{ \begin{bmatrix} a_{11}& \cdots &a_{1n}\\ \vdots & \ddots & \vdots\\ a_{n1} & \cdots &a_{nn} \end{bmatrix} }\ne \begin{bmatrix} e^{a_{11}}& \cdots &e^{a_{1n}}\\ \vdots & \ddots & \vdots\\ e^{a_{n1}} & \cdots &e^{a_{nn}} \end{bmatrix} $$ neigher $$\ln{ \begin{bmatrix} a_{11}& \cdots &a_{1n}\\ \vdots & \ddots & \vdots\\ a_{n1} & \cdots &a_{nn} \end{bmatrix} }\ne \begin{bmatrix} \ln{a_{11}}& \cdots &\ln{a_{1n}}\\ \vdots & \ddots & \vdots\\ \ln{a_{n1}} & \cdots &\ln{a_{nn}} \end{bmatrix} $$ They are acutally defined trough power series of $\ln$ and exponential. See link and link

However in matlab the regular

exp

and

log

do an elementwise evaluation of matrix and vector entries, e,g.

exp([a,b,c])

will return the value of

[exp(a),exp(b),exp(c)].

In matlab, the true matrix $\ln$ and exponential implemented via

logm

and

expm