I want to define this expression symbolically:

$V = \frac{1}{N} \sum_{i=1}^N ( y_i(g) - z_i)^2$

in which $\{y_i(g)\}_{i=1}^N$ is to be understood as a symbolic sequence that depends on a vector $g$. That is $y(g) = \{ y_1(g), \dots y_N(g)\}$

The motivation is that I would like to compute the derivative of V with respect to $g$.

Define $\{u_i\}_{i=1}^N$ and $\{z_i\}_{i=1}^N$ to be mutually independent (and independent from the rest) symbolic sequences of size $N$. Define $\{g\}_{k=1}^n$ as a finite sequence of size $n$.

We should also define $G = \sum_{k=1}^n g_k q^{-k}$ in which $q^-k$ is the backward shift operator, applied on sequences: $q^{-k} \;u_i = u_{i-k}$

Furthermore, define $C(G)$ to be some rational function in $G$.

Then $y(g) = \frac{ C(G) G} {1+ C(G) G} u$. This should return the finite sequence $\{y_i(g)\}_{i=1}^N$.

Then, we should ask for $\frac{\text{d} V}{\text{d} g}$.


1 Answer 1


If I understand you correctly, the main idea of the procedure can be outlined as follows.

Call the vector gg and let it have k components g[i]:

gg[k_] := Array[g, k]

Then your expression can be written as

V[n_, k_] := Sum[(y[i, gg[k]] - z[i])^2, {i, 1, n}]

Example n = 3, k = 2

V[3, 2]

(* Out[32]= (y[1, {g[1], g[2]}] - z[1])^2 + (y[2, {g[1], g[2]}] - 
   z[2])^2 + (y[3, {g[1], g[2]}] - z[3])^2 *)

Now the drivatives with respect to gg, i.e. to the g[i] become

With[{n = 3, k = 2},
 Table[{i, D[V[n, k], g[i]]}, {i, 1, k}]]

$\left\{\left\{1,2 (y[1,\{g[1],g[2]\}]-z[1]) y^{(0,\{1,0\})}[1,\{g[1],g[2]\}]+2 (y[2,\{g[1],g[2]\}]-z[2]) y^{(0,\{1,0\})}[2,\{g[1],g[2]\}]+2 (y[3,\{g[1],g[2]\}]-z[3]) y^{(0,\{1,0\})}[3,\{g[1],g[2]\}]\right\},\left\{2,2 (y[1,\{g[1],g[2]\}]-z[1]) y^{(0,\{0,1\})}[1,\{g[1],g[2]\}]+2 (y[2,\{g[1],g[2]\}]-z[2]) y^{(0,\{0,1\})}[2,\{g[1],g[2]\}]+2 (y[3,\{g[1],g[2]\}]-z[3]) y^{(0,\{0,1\})}[3,\{g[1],g[2]\}]\right\}\right\}$

If you define clearly the function y[i,gg] then MMA will perform the differentiation explicitly. I suggest to start with a simple example for y[i,gg].



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.