Vector / matrix differentials




On Tue, 1 Dec 2009, Ryan Mitchley wrote:

< Hi all
< 
< I have a function 1 / | s^H U |^2
< where s is a complex vector function of phi and theta, i.e. s(phi, theta)
< U is a complex matrix (columns are basis vectors),
< | | denotes the L2 vector norm
< ^H is hermitian transpose
< ^2 is the square operator.
< 
< The function could also be written as 1 / s^H U U^H s.
< 
< How do I instruct Maxima to find the partial derivatives of the function
< w.r.t. phi and theta. Assume that I can obtain the p.d.'s of s w.r.t.
< phi and theta.
< 
< I'm rather hazy on specifying the constraints (e.g. U is a complex
< matrix, s is a complex vector, etc.)
 
Ryan,
I just noticed that no-one had replied on-list to this question. Your basic 
problem is 2-fold: how to tell Maxima that some objects have some properties,
and how to make Maxima do the right thing.

I don't believe that the Maxima simplifier knows anything more sophisticated than
the difference between scalar and nonscalar, but this will suffice. Here's a bit of
code that does what you wish. I'm lazy, so I used x & y in place of your independent
variables. Leo.



/* We declare some properties of s and U: */
depends([s,U],[x,y]);
declare([s,U],complex);
declare([s,U],nonscalar);

/* We tell Maxima the chain rule for functions of s and U: */
matchdeclare(foo,atom,xx,atom);
tellsimpafter('diff(foo(s,U),xx,1),'diff(foo(s,U),s,1)*diff(s,xx)+'diff(foo(s,U),U,1)*diff(U,xx));

/* We tell Maxima the Liebnitz rule: */
tellsimpafter('diff(U . s,xx,1),'diff(U,xx,1) . s + U . 'diff(s,xx,1));

/* We tell Maxima how to differentiate ctranspose */
tellsimpafter('diff('transpose(conjugate(U . s)),xx,1),ctranspose('diff(U . s,xx)));

/* We tell Maxima that transpose(0) is 0*/
tellsimpafter('transpose(0),0);

g(s,U) := ctranspose(U . s) . U . s;
diff(g(s,U),x);
dg_dx : ''%;
diff(1/r,r);
subst(r=g(s,U),%)*dg_dx;  /* df_dx where f is 1/g */
subst('diff(U,x,1)=0,%);  /* df_dx when U is independent of x */

diff(g(s,U),y);
dg_dy : ''%;
diff(1/r,r);
subst(r=g(s,U),%)*dg_dy;
subst('diff(U,y,1)=0,%);


-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.